Multiple Linear Regression

Author

Josie Athens

Published

February 15, 2024

2 Univariate Analysis

2.1 Introduction

Example

We will use the kfm dataset from the ISwR package. Our interest will be to estimate the effect of mother weight on the daily breast-milk intake by infants, controlled by potential confounders.

kfm = read_rds("data/kfm.rds") |> rcopy
kfm |> schema
┌────────────┬───────────────┬──────────────────────────────────┐
│ names      │ scitypes      │ types                            │
├────────────┼───────────────┼──────────────────────────────────┤
│ no         │ Count         │ Int64                            │
│ dl_milk    │ Continuous    │ Float64                          │
│ sex        │ Multiclass{2} │ CategoricalValue{String, UInt32} │
│ weight     │ Continuous    │ Float64                          │
│ ml_suppl   │ Count         │ Int64                            │
│ mat_weight │ Count         │ Int64                            │
│ mat_height │ Count         │ Int64                            │
└────────────┴───────────────┴──────────────────────────────────┘
Exercise

Construct a table, with the descriptive statistics of all variables, stratified by sex.

Code
summarize_by(@select(kfm, {Not(:no)}), :sex)
     |            | Obs |  Mean   | Std. Dev. |  Min  |  Max   
---------------------------------------------------------------
 Boy |    dl_milk |  25 |   7.952 |     1.492 | 4.910 | 10.430 
     |     weight |  25 |   5.438 |     0.570 | 4.360 |  6.578 
     |   ml_suppl |  25 | 105.200 |   143.530 |     0 |    555 
     | mat_weight |  25 |  60.400 |     8.062 |    48 |     78 
     | mat_height |  25 | 168.200 |     7.483 |   153 |    185 
---------------------------------------------------------------
Girl |    dl_milk |  25 |   7.056 |     1.422 | 4.440 | 10.030 
     |     weight |  25 |   5.199 |     0.509 | 4.120 |  6.100 
     |   ml_suppl |  25 |  86.800 |   117.658 |     0 |    590 
     | mat_weight |  25 |  59.520 |     8.832 |    47 |     80 
     | mat_height |  25 | 166.680 |     5.437 |   157 |    176 

We would like to check if the distributions of our outcome and our primary predictor are normal or close to normal.

let
    kfm_comb = DataFrames.combine(groupby(kfm, :sex), :dl_milk=>(x->fit(Normal, x))=>:d)
    
    plot(
        kfm_comb,
        x=:d, y=kfm.dl_milk, color=:sex,
        Stat.qq,
        Guide.xlabel("Theoretical quantiles"),
        Guide.ylabel("Breast-milk intake (dl/day)")
    )
end
Theoretical quantiles 0 5 10 15 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 1.05 1.10 1.15 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.80 1.85 1.90 1.95 2.00 2.05 2.10 2.15 2.20 2.25 2.30 2.35 2.40 2.45 2.50 2.55 2.60 2.65 2.70 2.75 2.80 2.85 2.90 2.95 3.00 3.05 3.10 3.15 3.20 3.25 3.30 3.35 3.40 3.45 3.50 3.55 3.60 3.65 3.70 3.75 3.80 3.85 3.90 3.95 4.00 4.05 4.10 4.15 4.20 4.25 4.30 4.35 4.40 4.45 4.50 4.55 4.60 4.65 4.70 4.75 4.80 4.85 4.90 4.95 5.00 5.05 5.10 5.15 5.20 5.25 5.30 5.35 5.40 5.45 5.50 5.55 5.60 5.65 5.70 5.75 5.80 5.85 5.90 5.95 6.00 6.05 6.10 6.15 6.20 6.25 6.30 6.35 6.40 6.45 6.50 6.55 6.60 6.65 6.70 6.75 6.80 6.85 6.90 6.95 7.00 7.05 7.10 7.15 7.20 7.25 7.30 7.35 7.40 7.45 7.50 7.55 7.60 7.65 7.70 7.75 7.80 7.85 7.90 7.95 8.00 8.05 8.10 8.15 8.20 8.25 8.30 8.35 8.40 8.45 8.50 8.55 8.60 8.65 8.70 8.75 8.80 8.85 8.90 8.95 9.00 9.05 9.10 9.15 9.20 9.25 9.30 9.35 9.40 9.45 9.50 9.55 9.60 9.65 9.70 9.75 9.80 9.85 9.90 9.95 10.00 10.05 10.10 10.15 10.20 10.25 10.30 10.35 10.40 10.45 10.50 10.55 10.60 10.65 10.70 10.75 10.80 10.85 10.90 10.95 11.00 11.05 11.10 11.15 11.20 11.25 11.30 11.35 11.40 11.45 11.50 11.55 11.60 11.65 11.70 11.75 11.80 11.85 11.90 11.95 12.00 12.05 12.10 12.15 12.20 12.25 12.30 12.35 12.40 12.45 12.50 12.55 12.60 12.65 12.70 12.75 12.80 12.85 12.90 12.95 13.00 13.05 13.10 13.15 13.20 13.25 13.30 13.35 13.40 13.45 13.50 13.55 13.60 13.65 13.70 13.75 13.80 13.85 13.90 13.95 14.00 14.05 14.10 14.15 14.20 14.25 14.30 14.35 14.40 14.45 14.50 14.55 14.60 14.65 14.70 14.75 14.80 14.85 14.90 14.95 15.00 0 20 Boy Girl sex 10.29712787155685710.390799999999999 9.67644678431629210.1996 9.3477696842054629.921999999999999 9.1122563794272059.7298 8.9241439668826379.6418 8.765019724592879.5091 8.6255235033605929.212700000000002 8.5002075275949438.925 8.3856035831987898.7102 8.2793568171879818.639 8.1797882260644928.5323 8.0856534507349658.4373 7.9960005459592278.4275 7.9100814988852518.4177 7.8272947162930878.405800000000001 7.74714623735393558.39 7.66922273084366258.3628 7.59317216073418958.204500000000001 7.5186895831994228.058700000000002 7.4455064574181238.036800000000001 7.37338240665651157.9129000000000005 7.3020987099848787.7379 7.2314530235287857.7095 7.1612549714843197.6994 7.0913223392640727.6796 7.0214776607359287.6404 6.9515450285156817.4266 6.8813469764712157.3629999999999995 6.8107012900151227.2484 6.73941759334348867.2218 6.6672935425818777.033099999999999 6.5941104168005786.975199999999999 6.51962783926581056.919 6.4435772691563386.901700000000001 6.36565376264606456.8919 6.2855052837069136.8505 6.2027185011147496.7938 6.1167994540407736.555000000000001 6.0271465492650366.4654 5.9330117739355086.4458 5.8334431828120196.3365 5.72719641680121156.0756 5.6125924724050565.8725000000000005 5.4872764966394085.694000000000001 5.347780275407135.3454999999999995 5.1886560331173635.087400000000001 5.00054362057279445.0129 4.7650303157945374.9505 4.4363532156837084.7616 3.81567212844314254.5331 11.35232239119248910.390799999999999 10.70115154009442410.1996 10.3563288100074999.921999999999999 10.1092463673972639.7298 9.9118932946246769.6418 9.7449523801804729.5091 9.5986036755524229.212700000000002 9.467131793658478.925 9.3468981510588278.7102 9.2354322171486178.639 9.1309725106143528.5323 9.032213545617098.4373 8.9381566144388358.4275 8.8480169595358168.4177 8.761163435578978.405800000000001 8.677077816864458.39 8.5953264680672338.3628 8.515540060066888.204500000000001 8.4373986692587328.058700000000002 8.3606205632705338.036800000000001 8.2849535573240897.9129000000000005 8.2101681862449577.7379 8.1360521664053017.7095 8.0624057701562347.6994 7.98903783196942557.6796 7.91576216803057257.6404 7.8423942298437647.4266 7.7687478335946967.3629999999999995 7.69463181375504057.2484 7.6198464426759097.2218 7.5441794367294647.033099999999999 7.4674013307412676.975199999999999 7.3892599399331186.919 7.3094735319327656.901700000000001 7.2277221831355476.8919 7.1436365644210286.8505 7.05678304046418256.7938 6.9666433855611636.555000000000001 6.8725864543829076.4654 6.7738274893856456.4458 6.6693677828513816.3365 6.5579018489411716.0756 6.4376682063415275.8725000000000005 6.3061963244475755.694000000000001 6.1598476198195265.3454999999999995 5.9929067053753235.087400000000001 5.7955536326027355.0129 5.5484711899924974.9505 5.2036484599055744.7616 4.5524776088075094.5331 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? 4 6 8 10 12 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 1.05 1.10 1.15 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.80 1.85 1.90 1.95 2.00 2.05 2.10 2.15 2.20 2.25 2.30 2.35 2.40 2.45 2.50 2.55 2.60 2.65 2.70 2.75 2.80 2.85 2.90 2.95 3.00 3.05 3.10 3.15 3.20 3.25 3.30 3.35 3.40 3.45 3.50 3.55 3.60 3.65 3.70 3.75 3.80 3.85 3.90 3.95 4.00 4.05 4.10 4.15 4.20 4.25 4.30 4.35 4.40 4.45 4.50 4.55 4.60 4.65 4.70 4.75 4.80 4.85 4.90 4.95 5.00 5.05 5.10 5.15 5.20 5.25 5.30 5.35 5.40 5.45 5.50 5.55 5.60 5.65 5.70 5.75 5.80 5.85 5.90 5.95 6.00 6.05 6.10 6.15 6.20 6.25 6.30 6.35 6.40 6.45 6.50 6.55 6.60 6.65 6.70 6.75 6.80 6.85 6.90 6.95 7.00 7.05 7.10 7.15 7.20 7.25 7.30 7.35 7.40 7.45 7.50 7.55 7.60 7.65 7.70 7.75 7.80 7.85 7.90 7.95 8.00 8.05 8.10 8.15 8.20 8.25 8.30 8.35 8.40 8.45 8.50 8.55 8.60 8.65 8.70 8.75 8.80 8.85 8.90 8.95 9.00 9.05 9.10 9.15 9.20 9.25 9.30 9.35 9.40 9.45 9.50 9.55 9.60 9.65 9.70 9.75 9.80 9.85 9.90 9.95 10.00 10.05 10.10 10.15 10.20 10.25 10.30 10.35 10.40 10.45 10.50 10.55 10.60 10.65 10.70 10.75 10.80 10.85 10.90 10.95 11.00 11.05 11.10 11.15 11.20 11.25 11.30 11.35 11.40 11.45 11.50 11.55 11.60 11.65 11.70 11.75 11.80 11.85 11.90 11.95 12.00 4 6 8 10 12 Breast-milk intake (dl/day)
Figure 1: QQ-Plots of outcome of interest, daily breast milk intake by sex.
let
    kfm_comb = DataFrames.combine(groupby(kfm, :sex), :mat_weight=>(x->fit(Normal, x))=>:d)
    
    plot(
        kfm_comb,
        x=:d, y=kfm.mat_weight, color=:sex,
        Stat.qq,
        Guide.xlabel("Theoretical quantiles"),
        Guide.ylabel("Maternal weight")
    )
end
Theoretical quantiles 30 40 50 60 70 80 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 30.0 30.2 30.4 30.6 30.8 31.0 31.2 31.4 31.6 31.8 32.0 32.2 32.4 32.6 32.8 33.0 33.2 33.4 33.6 33.8 34.0 34.2 34.4 34.6 34.8 35.0 35.2 35.4 35.6 35.8 36.0 36.2 36.4 36.6 36.8 37.0 37.2 37.4 37.6 37.8 38.0 38.2 38.4 38.6 38.8 39.0 39.2 39.4 39.6 39.8 40.0 40.2 40.4 40.6 40.8 41.0 41.2 41.4 41.6 41.8 42.0 42.2 42.4 42.6 42.8 43.0 43.2 43.4 43.6 43.8 44.0 44.2 44.4 44.6 44.8 45.0 45.2 45.4 45.6 45.8 46.0 46.2 46.4 46.6 46.8 47.0 47.2 47.4 47.6 47.8 48.0 48.2 48.4 48.6 48.8 49.0 49.2 49.4 49.6 49.8 50.0 50.2 50.4 50.6 50.8 51.0 51.2 51.4 51.6 51.8 52.0 52.2 52.4 52.6 52.8 53.0 53.2 53.4 53.6 53.8 54.0 54.2 54.4 54.6 54.8 55.0 55.2 55.4 55.6 55.8 56.0 56.2 56.4 56.6 56.8 57.0 57.2 57.4 57.6 57.8 58.0 58.2 58.4 58.6 58.8 59.0 59.2 59.4 59.6 59.8 60.0 60.2 60.4 60.6 60.8 61.0 61.2 61.4 61.6 61.8 62.0 62.2 62.4 62.6 62.8 63.0 63.2 63.4 63.6 63.8 64.0 64.2 64.4 64.6 64.8 65.0 65.2 65.4 65.6 65.8 66.0 66.2 66.4 66.6 66.8 67.0 67.2 67.4 67.6 67.8 68.0 68.2 68.4 68.6 68.8 69.0 69.2 69.4 69.6 69.8 70.0 70.2 70.4 70.6 70.8 71.0 71.2 71.4 71.6 71.8 72.0 72.2 72.4 72.6 72.8 73.0 73.2 73.4 73.6 73.8 74.0 74.2 74.4 74.6 74.8 75.0 75.2 75.4 75.6 75.8 76.0 76.2 76.4 76.6 76.8 77.0 77.2 77.4 77.6 77.8 78.0 78.2 78.4 78.6 78.8 79.0 79.2 79.4 79.6 79.8 80.0 0 20 40 60 80 Boy Girl sex 79.6519300908752779.02 75.7961579457575678.0 73.7543621936433777.1 72.2913151328640675.14 71.1227301455803873.59 70.1342243998010771.83 69.2676511221008669.26 68.4891678419938368.0 67.7772294478535167.67 67.1172072088731167.0 66.4986708814825466.42 65.9138903040427265.0 65.3569518374623964.5 64.8232087039061263.0 64.3089237081735862.79 63.8110282850327862.0 63.3269547535063462.0 62.85451620837185561.85 62.3918182888462160.870000000000005 61.937192775549759.89 61.48914640900737559.0 61.0463204591311659.0 60.60745793277139659.0 60.1713761843844558.97 59.7369432672347158.0 59.303056732765358.0 58.8686238156155658.0 58.4325420672286158.0 57.9936795408688558.0 57.5508535909926358.0 57.1028072244503158.0 56.64818171115379657.13 56.1854837916281557.0 55.71304524649366456.17 55.2289717149672256.0 54.7310762918264255.209999999999994 54.2167912960938955.0 53.6830481625376255.0 53.12610969595727554.269999999999996 52.5413291185174754.0 51.922792791126953.31 51.2627705521464952.33 50.5508321580061751.35 49.7723488778991550.37 48.90577560019893649.39 47.9172698544196349.0 46.7486848671359548.43 45.28563780635662548.0 43.2438420542424548.0 39.3880699091247447.489999999999995 78.7766757738659679.02 75.2570790810060478.0 73.3933025646120377.1 72.0578150402422375.14 70.9911161530226373.59 70.0887958335703371.83 69.29777698506969.26 68.587167780222568.0 67.9373015736031267.67 67.3348250780791667.0 66.7702174378029766.42 66.2364224652416365.0 65.728042117200464.5 65.2408347571700663.0 64.7713890269653562.79 64.3169039021388362.0 63.87503557161032662.0 63.4437878011370761.85 63.02143139467314460.870000000000005 62.60644358085373559.89 62.1974612938876859.0 61.7932442680786259.0 61.3926451044709359.0 60.9945842695269658.97 60.5980285082105658.0 60.20197149178943658.0 59.8054157304730458.0 59.4073548955290758.0 59.0067557319213758.0 58.6025387061123258.0 58.1935564191462658.0 57.7785686053268557.13 57.3562121988629357.0 56.9249644283896756.17 56.48309609786116456.0 56.0286109730346455.209999999999994 55.5591652428299455.0 55.07195788279959555.0 54.5635775347583654.269999999999996 54.0297825621970254.0 53.46517492192083453.31 52.86269842639687552.33 52.212832219777551.35 51.5022230149309950.37 50.7112041664296749.39 49.8088838469773749.0 48.7421849597577748.43 47.40669743538795448.0 45.5429209189939648.0 42.0233242261340447.489999999999995 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? 40 50 60 70 80 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 40.0 40.2 40.4 40.6 40.8 41.0 41.2 41.4 41.6 41.8 42.0 42.2 42.4 42.6 42.8 43.0 43.2 43.4 43.6 43.8 44.0 44.2 44.4 44.6 44.8 45.0 45.2 45.4 45.6 45.8 46.0 46.2 46.4 46.6 46.8 47.0 47.2 47.4 47.6 47.8 48.0 48.2 48.4 48.6 48.8 49.0 49.2 49.4 49.6 49.8 50.0 50.2 50.4 50.6 50.8 51.0 51.2 51.4 51.6 51.8 52.0 52.2 52.4 52.6 52.8 53.0 53.2 53.4 53.6 53.8 54.0 54.2 54.4 54.6 54.8 55.0 55.2 55.4 55.6 55.8 56.0 56.2 56.4 56.6 56.8 57.0 57.2 57.4 57.6 57.8 58.0 58.2 58.4 58.6 58.8 59.0 59.2 59.4 59.6 59.8 60.0 60.2 60.4 60.6 60.8 61.0 61.2 61.4 61.6 61.8 62.0 62.2 62.4 62.6 62.8 63.0 63.2 63.4 63.6 63.8 64.0 64.2 64.4 64.6 64.8 65.0 65.2 65.4 65.6 65.8 66.0 66.2 66.4 66.6 66.8 67.0 67.2 67.4 67.6 67.8 68.0 68.2 68.4 68.6 68.8 69.0 69.2 69.4 69.6 69.8 70.0 70.2 70.4 70.6 70.8 71.0 71.2 71.4 71.6 71.8 72.0 72.2 72.4 72.6 72.8 73.0 73.2 73.4 73.6 73.8 74.0 74.2 74.4 74.6 74.8 75.0 75.2 75.4 75.6 75.8 76.0 76.2 76.4 76.6 76.8 77.0 77.2 77.4 77.6 77.8 78.0 78.2 78.4 78.6 78.8 79.0 79.2 79.4 79.6 79.8 80.0 40 60 80 Maternal weight
Figure 2: QQ-Plots of main predictor of interest, maternal weight by sex.
Question

What are your main observations about the descriptive statistics of daily breast-milk intake and maternal weight?

Answer

Boys have a higher mean breast-milk intake than girls (about 1 dl/day more), but we do not know if that difference is statistically significant or not. The distribution of daily breast-milk intake is normal for each sex. There is more variability in the distribution of breast-milk intake than in the distribution of mother weight. There are deviations from normality for higher values of maternal weight in the boy’s group.

We can plot the linear relationship between maternal weight and breast-milk intake for all the cases (unadjusted).

plot(
    kfm,
    x = :mat_weight, y = :dl_milk,
    Geom.point, 
    layer(Stat.smooth(method=:lm), Geom.line, Geom.ribbon),
    Guide.xlabel("Maternal weight (kg)"),
    Guide.ylabel("Breast milk intake (dl/day) ")
)
Maternal weight (kg) 40 50 60 70 80 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 40.0 40.2 40.4 40.6 40.8 41.0 41.2 41.4 41.6 41.8 42.0 42.2 42.4 42.6 42.8 43.0 43.2 43.4 43.6 43.8 44.0 44.2 44.4 44.6 44.8 45.0 45.2 45.4 45.6 45.8 46.0 46.2 46.4 46.6 46.8 47.0 47.2 47.4 47.6 47.8 48.0 48.2 48.4 48.6 48.8 49.0 49.2 49.4 49.6 49.8 50.0 50.2 50.4 50.6 50.8 51.0 51.2 51.4 51.6 51.8 52.0 52.2 52.4 52.6 52.8 53.0 53.2 53.4 53.6 53.8 54.0 54.2 54.4 54.6 54.8 55.0 55.2 55.4 55.6 55.8 56.0 56.2 56.4 56.6 56.8 57.0 57.2 57.4 57.6 57.8 58.0 58.2 58.4 58.6 58.8 59.0 59.2 59.4 59.6 59.8 60.0 60.2 60.4 60.6 60.8 61.0 61.2 61.4 61.6 61.8 62.0 62.2 62.4 62.6 62.8 63.0 63.2 63.4 63.6 63.8 64.0 64.2 64.4 64.6 64.8 65.0 65.2 65.4 65.6 65.8 66.0 66.2 66.4 66.6 66.8 67.0 67.2 67.4 67.6 67.8 68.0 68.2 68.4 68.6 68.8 69.0 69.2 69.4 69.6 69.8 70.0 70.2 70.4 70.6 70.8 71.0 71.2 71.4 71.6 71.8 72.0 72.2 72.4 72.6 72.8 73.0 73.2 73.4 73.6 73.8 74.0 74.2 74.4 74.6 74.8 75.0 75.2 75.4 75.6 75.8 76.0 76.2 76.4 76.6 76.8 77.0 77.2 77.4 77.6 77.8 78.0 78.2 78.4 78.6 78.8 79.0 79.2 79.4 79.6 79.8 80.0 40 60 80 47,5.82 67,6.97 48,4.63 62,9.03 48,7.24 51,6.46 59,7.36 55,8.23 49,6.91 50,7.68 55,5.03 74,7.93 58,7.74 65,5.17 70,8.57 58,4.44 61,8.06 63,7.01 58,7.22 53,6.89 59,6.9 80,8.67 73,5.0 67,7.42 58,10.03 63,7.7 49,4.91 78,10.35 54,6.84 52,5.62 76,10.43 59,8.39 60,5.97 68,9.63 59,6.78 62,9.32 56,8.39 68,7.71 54,8.73 58,7.64 58,6.48 57,8.05 57,8.43 78,9.79 56,6.29 58,6.44 55,9.65 62,8.41 48,8.44 65,8.42 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? 4 6 8 10 12 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 1.05 1.10 1.15 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.80 1.85 1.90 1.95 2.00 2.05 2.10 2.15 2.20 2.25 2.30 2.35 2.40 2.45 2.50 2.55 2.60 2.65 2.70 2.75 2.80 2.85 2.90 2.95 3.00 3.05 3.10 3.15 3.20 3.25 3.30 3.35 3.40 3.45 3.50 3.55 3.60 3.65 3.70 3.75 3.80 3.85 3.90 3.95 4.00 4.05 4.10 4.15 4.20 4.25 4.30 4.35 4.40 4.45 4.50 4.55 4.60 4.65 4.70 4.75 4.80 4.85 4.90 4.95 5.00 5.05 5.10 5.15 5.20 5.25 5.30 5.35 5.40 5.45 5.50 5.55 5.60 5.65 5.70 5.75 5.80 5.85 5.90 5.95 6.00 6.05 6.10 6.15 6.20 6.25 6.30 6.35 6.40 6.45 6.50 6.55 6.60 6.65 6.70 6.75 6.80 6.85 6.90 6.95 7.00 7.05 7.10 7.15 7.20 7.25 7.30 7.35 7.40 7.45 7.50 7.55 7.60 7.65 7.70 7.75 7.80 7.85 7.90 7.95 8.00 8.05 8.10 8.15 8.20 8.25 8.30 8.35 8.40 8.45 8.50 8.55 8.60 8.65 8.70 8.75 8.80 8.85 8.90 8.95 9.00 9.05 9.10 9.15 9.20 9.25 9.30 9.35 9.40 9.45 9.50 9.55 9.60 9.65 9.70 9.75 9.80 9.85 9.90 9.95 10.00 10.05 10.10 10.15 10.20 10.25 10.30 10.35 10.40 10.45 10.50 10.55 10.60 10.65 10.70 10.75 10.80 10.85 10.90 10.95 11.00 11.05 11.10 11.15 11.20 11.25 11.30 11.35 11.40 11.45 11.50 11.55 11.60 11.65 11.70 11.75 11.80 11.85 11.90 11.95 12.00 4 6 8 10 12 Breast milk intake (dl/day)
Figure 3: Relationship between breast-milk intake in infants and maternal weight. The black line shows a linear model fit with a 95% CIs band.
Interpretation

The scatter plot shows a positive effect of maternal weight on breast-milk intake. As maternal weight increases, the daily breast-milk intake of the babies also increases. It also shows dispersion in the values of breast-milk intake that are not accounted by the model. We already know that a simple linear regression model would not be good for making predictions.

2.1.1 Simple Linear Regression

A univariate analysis is what people from epidemiology call unadjusted. We will perform the univariate analysis to understand concepts like confounding and interactions better.

model_1 = lm(@formula(dl_milk ~ mat_weight), kfm)
StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}}, Matrix{Float64}}

dl_milk ~ 1 + mat_weight

Coefficients:
─────────────────────────────────────────────────────────────────────────
                 Coef.  Std. Error     t  Pr(>|t|)   Lower 95%  Upper 95%
─────────────────────────────────────────────────────────────────────────
(Intercept)  2.80837     1.41935    1.98    0.0536  -0.045414    5.66216
mat_weight   0.0783193   0.0234481  3.34    0.0016   0.0311737   0.125465
─────────────────────────────────────────────────────────────────────────

Corresponding coefficient of determination:

model_1 |> r2 |> r3
0.189
Question

What are your conclusions from the univariate analysis?

Answer

Maternal weight has a significant effect on daily breast-milk intake ( \(p\) = 0.002). For each kg of increase in maternal weight, a simple linear regression model predicts a 0.08 dl/day increase in breast-milk intake by the infant (95% CI: 0.03, 0.13 dl/day). The simple linear model explains about only 19% of the variability in the data.

2.2 Centring

The value of the intercept of \(\beta_0\) = 2.81 is the predicted consumption of breast-milk intake in a day by an infant born from a mother with a weight of 0 kg. To make a better interpretation of this coefficient, we could centre the values of maternal weight. Centring involves removing the mean value to each one of the observations. By definition, the mean of the centre variable is zero, so the intercept would represent the value for the average maternal weight.

model_2 = lm(
    @formula(dl_milk ~ mat_weight),
    kfm;
    contrasts = Dict(:mat_weight => Center())
)
StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}}, Matrix{Float64}}

dl_milk ~ 1 + mat_weight(centered: 59.96)

Coefficients:
─────────────────────────────────────────────────────────────────────────────────────────
                                 Coef.  Std. Error      t  Pr(>|t|)  Lower 95%  Upper 95%
─────────────────────────────────────────────────────────────────────────────────────────
(Intercept)                  7.5044      0.194547   38.57    <1e-37  7.11324     7.89556
mat_weight(centered: 59.96)  0.0783193   0.0234481   3.34    0.0016  0.0311737   0.125465
─────────────────────────────────────────────────────────────────────────────────────────
Interpretation

As our model has only one predictor (univariate analysis) the value of the coefficient of interest (slope) is the same. The model predicts that the daily breast-milk intake of an infant from a mother with an average weight (59.96 kg) is 7.50 dl/day (95% CIs: 7.11 (dl/day), 7.90 (dl/day)). This value is our best estimate for the mean daily breast-milk intake in the population.

Let’s check descriptive statistics!

estat(
    @select(kfm, :dl_milk, :mat_weight),
    ["Breast-milk intake (dl/day)", "Maternal weight (kg)"]
)
2×6 DataFrame
Row Variable n Median Mean SD CV
String Int64 Float64 Float64 Float64 Float64
1 Breast-milk intake (dl/day) 50 7.66 7.504 1.512 0.201
2 Maternal weight (kg) 50 58.0 59.96 8.381 0.14

YAY!!

3 Multivariate Analysis

For the multivariate analysis, we will start by controlling by all potential confounders.

kfm_cont = Dict(
    :mat_weight => Center(),
    :mat_height => Center(),
    :sex => EffectsCoding()
);
model_3 = lm(
    @formula(dl_milk ~ mat_weight + sex  + ml_suppl + mat_height),
    kfm; contrasts = kfm_cont
)
StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}}, Matrix{Float64}}

dl_milk ~ 1 + mat_weight(centered: 59.96) + sex + ml_suppl + mat_height(centered: 167.44)

Coefficients:
────────────────────────────────────────────────────────────────────────────────────────────────
                                    Coef.  Std. Error      t  Pr(>|t|)    Lower 95%    Upper 95%
────────────────────────────────────────────────────────────────────────────────────────────────
(Intercept)                    7.65913     0.225182    34.01    <1e-33   7.20559      8.11267
mat_weight(centered: 59.96)    0.0336862   0.026633     1.26    0.2124  -0.0199554    0.0873278
sex: Girl                     -0.378385    0.179204    -2.11    0.0403  -0.73932     -0.017449
ml_suppl                      -0.00161181  0.00144043  -1.12    0.2691  -0.00451299   0.00128937
mat_height(centered: 167.44)   0.0916081   0.0348551    2.63    0.0117   0.0214064    0.16181
────────────────────────────────────────────────────────────────────────────────────────────────
anova(model_3)
Analysis of Variance

Type 1 test / F test

dl_milk ~ 1 + mat_weight(centered: 59.96) + sex + ml_suppl + mat_height(centered: 167.44)

Table:
──────────────────────────────────────────────────────────────────────────────
                              DOF     Exp.SS  Mean Square    F value  Pr(>|F|)
──────────────────────────────────────────────────────────────────────────────
(Intercept)                     1  2815.80      2815.80    1782.9896    <1e-37
mat_weight(centered: 59.96)     1    21.11        21.11      13.3686    0.0007
sex                             1     8.5749       8.5749     5.4297    0.0243
ml_suppl                        1     0.2856       0.2856     0.1808    0.6727
mat_height(centered: 167.44)    1    10.91        10.91       6.9077    0.0117
(Residuals)                    45    71.07         1.5793               
──────────────────────────────────────────────────────────────────────────────
Note

anova reports, by default, Type 1 ANOVA tests. In type 1 ANOVA the tests are successive. A more appropriate ANOVA table is obtained with type 3 ANOVA (Type 2 in R). Type 3 tests are calculated according to the principle of marginality, testing each term after all others, except ignoring the term’s higher-order relatives. We can use Type 3 ANOVA for model simplification.

anova(model_3; type=3)
Analysis of Variance

Type 3 test / F test

dl_milk ~ 1 + mat_weight(centered: 59.96) + sex + ml_suppl + mat_height(centered: 167.44)

Table:
──────────────────────────────────────────────────────────────────────────────
                              DOF     Exp.SS  Mean Square    F value  Pr(>|F|)
──────────────────────────────────────────────────────────────────────────────
(Intercept)                     1  1827.03      1827.03    1156.8898    <1e-33
mat_weight(centered: 59.96)     1     2.5265       2.5265     1.5998    0.2124
sex                             1     7.0408       7.0408     4.4583    0.0403
ml_suppl                        1     1.9774       1.9774     1.2521    0.2691
mat_height(centered: 167.44)    1    10.91        10.91       6.9077    0.0117
(Residuals)                    45    71.07         1.5793               
──────────────────────────────────────────────────────────────────────────────

3.1 Model Simplification

ANOVA reports \(p\)-values from \(F\)-tests. A summary of a regression model reports \(p\)-values from \(t\)-tests. \(F\)-tests compares a model that includes a particular parameter, against the model that does not have such parameter. In other words, it tests if removing a particular variable from a model is significant or not. \(t\)-tests, tests the slope of a parameter, i.e., against the null value of zero (no effect), adjusted by the other parameters in the model.

For model simplification, we are interested in removing parameters which do not have a significant contribution to the model, i.e., that if we remove them, the model would not be significantly different from the model that contains the parameter.

We will remove, one parameter at a time, starting with the one with the highest non-significant \(p\)-value (as long as the parameter is not our predictor of interest). For model simplification, we start looking first at interaction terms, but as currently, we do not have any, we remove ml_suppl.

model_4 = lm(
    @formula(dl_milk ~ mat_weight + sex + mat_height),
    kfm; contrasts = kfm_cont
)

anova(model_4; type=3)
Analysis of Variance

Type 3 test / F test

dl_milk ~ 1 + mat_weight(centered: 59.96) + sex + mat_height(centered: 167.44)

Table:
──────────────────────────────────────────────────────────────────────────────
                              DOF     Exp.SS  Mean Square    F value  Pr(>|F|)
──────────────────────────────────────────────────────────────────────────────
(Intercept)                     1  2815.80      2815.80    1773.2709    <1e-37
mat_weight(centered: 59.96)     1     3.8154       3.8154     2.4028    0.1280
sex                             1     6.6982       6.6982     4.2183    0.0457
mat_height(centered: 167.44)    1     9.2173       9.2173     5.8047    0.0200
(Residuals)                    46    73.04         1.5879               
──────────────────────────────────────────────────────────────────────────────

We can use information criteria (IC) for model simplification. Both Akaike’s information criterion (AIC) and Bayesian information criterion (BIC) penalise the number of parameters in the model. The more parameters included in the model, the more penalty is given. It can be calculated with the following formula:

\[IC = -2 × \mathbf{log-likelihood} + k(p)\]

where \(p\) is the number of parameters in the model (including the intercept). For AIC, \(k\) = 2, whereas for BIC, \(k = log(n)\), where \(n\) is the number of observations.

aic(model_3) |> r3, aic(model_4) |> r3
(171.474, 170.846)
bic(model_3) |> r3, bic(model_4) |> r3
(182.946, 180.406)
Interpretation

As the BIC value for model_3 is higher than the BIC for model_4, we prefer the latter over the former.

Another way to look at coefficients is through a plot of coefficients. In these kind of plots, the intercept is omitted by default.

coef_plot(model_4, ["Maternal\n Weight", "Sex\n Girl-Boy", "Maternal\n Height"])
Coefficients -0.75 -0.50 -0.25 0.00 0.25 -0.75 -0.70 -0.65 -0.60 -0.55 -0.50 -0.45 -0.40 -0.35 -0.30 -0.25 -0.20 -0.15 -0.10 -0.05 0.00 0.05 0.10 0.15 0.20 0.25 -0.750 -0.745 -0.740 -0.735 -0.730 -0.725 -0.720 -0.715 -0.710 -0.705 -0.700 -0.695 -0.690 -0.685 -0.680 -0.675 -0.670 -0.665 -0.660 -0.655 -0.650 -0.645 -0.640 -0.635 -0.630 -0.625 -0.620 -0.615 -0.610 -0.605 -0.600 -0.595 -0.590 -0.585 -0.580 -0.575 -0.570 -0.565 -0.560 -0.555 -0.550 -0.545 -0.540 -0.535 -0.530 -0.525 -0.520 -0.515 -0.510 -0.505 -0.500 -0.495 -0.490 -0.485 -0.480 -0.475 -0.470 -0.465 -0.460 -0.455 -0.450 -0.445 -0.440 -0.435 -0.430 -0.425 -0.420 -0.415 -0.410 -0.405 -0.400 -0.395 -0.390 -0.385 -0.380 -0.375 -0.370 -0.365 -0.360 -0.355 -0.350 -0.345 -0.340 -0.335 -0.330 -0.325 -0.320 -0.315 -0.310 -0.305 -0.300 -0.295 -0.290 -0.285 -0.280 -0.275 -0.270 -0.265 -0.260 -0.255 -0.250 -0.245 -0.240 -0.235 -0.230 -0.225 -0.220 -0.215 -0.210 -0.205 -0.200 -0.195 -0.190 -0.185 -0.180 -0.175 -0.170 -0.165 -0.160 -0.155 -0.150 -0.145 -0.140 -0.135 -0.130 -0.125 -0.120 -0.115 -0.110 -0.105 -0.100 -0.095 -0.090 -0.085 -0.080 -0.075 -0.070 -0.065 -0.060 -0.055 -0.050 -0.045 -0.040 -0.035 -0.030 -0.025 -0.020 -0.015 -0.010 -0.005 0.000 0.005 0.010 0.015 0.020 0.025 0.030 0.035 0.040 0.045 0.050 0.055 0.060 0.065 0.070 0.075 0.080 0.085 0.090 0.095 0.100 0.105 0.110 0.115 0.120 0.125 0.130 0.135 0.140 0.145 0.150 0.155 0.160 0.165 0.170 0.175 0.180 0.185 0.190 0.195 0.200 0.205 0.210 0.215 0.220 0.225 0.230 0.235 0.240 0.245 0.250 -0.75 -0.50 -0.25 0.00 0.25 0.081079317479535263 -0.368626313074335852 0.040348649184584371 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? Maternal Weight Sex Girl-Boy Maternal Height Predictors
Figure 4: Coefficient plot showing the effect of different predictors on daily breast-milk intake.
Note

Function coef_plot takes as arguments, the name of the regression model and a string vector with the names to be used for the variables. The order of the names should be the same as in the coefficients of the model, omitting the intercept.

A third argument, ratio is a logical that we can use to back transform (exponentiate) the coefficients.

3.2 Interactions

Let’s make a quick plot to see if sex appears to affect the relationship between maternal weight and daily breast-milk intake.

plot(
    kfm,
    x = :mat_weight, y = :dl_milk, color = :sex,
    Geom.point, Geom.smooth(method = :lm),
    Guide.xlabel("Maternal weight (kg)"),
    Guide.ylabel("Breast milk intake (dl/day) ")
)
Maternal weight (kg) 40 50 60 70 80 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 40.0 40.2 40.4 40.6 40.8 41.0 41.2 41.4 41.6 41.8 42.0 42.2 42.4 42.6 42.8 43.0 43.2 43.4 43.6 43.8 44.0 44.2 44.4 44.6 44.8 45.0 45.2 45.4 45.6 45.8 46.0 46.2 46.4 46.6 46.8 47.0 47.2 47.4 47.6 47.8 48.0 48.2 48.4 48.6 48.8 49.0 49.2 49.4 49.6 49.8 50.0 50.2 50.4 50.6 50.8 51.0 51.2 51.4 51.6 51.8 52.0 52.2 52.4 52.6 52.8 53.0 53.2 53.4 53.6 53.8 54.0 54.2 54.4 54.6 54.8 55.0 55.2 55.4 55.6 55.8 56.0 56.2 56.4 56.6 56.8 57.0 57.2 57.4 57.6 57.8 58.0 58.2 58.4 58.6 58.8 59.0 59.2 59.4 59.6 59.8 60.0 60.2 60.4 60.6 60.8 61.0 61.2 61.4 61.6 61.8 62.0 62.2 62.4 62.6 62.8 63.0 63.2 63.4 63.6 63.8 64.0 64.2 64.4 64.6 64.8 65.0 65.2 65.4 65.6 65.8 66.0 66.2 66.4 66.6 66.8 67.0 67.2 67.4 67.6 67.8 68.0 68.2 68.4 68.6 68.8 69.0 69.2 69.4 69.6 69.8 70.0 70.2 70.4 70.6 70.8 71.0 71.2 71.4 71.6 71.8 72.0 72.2 72.4 72.6 72.8 73.0 73.2 73.4 73.6 73.8 74.0 74.2 74.4 74.6 74.8 75.0 75.2 75.4 75.6 75.8 76.0 76.2 76.4 76.6 76.8 77.0 77.2 77.4 77.6 77.8 78.0 78.2 78.4 78.6 78.8 79.0 79.2 79.4 79.6 79.8 80.0 40 60 80 Boy Girl sex 47,5.82 67,6.97 48,4.63 62,9.03 48,7.24 51,6.46 59,7.36 55,8.23 49,6.91 50,7.68 55,5.03 74,7.93 58,7.74 65,5.17 70,8.57 58,4.44 61,8.06 63,7.01 58,7.22 53,6.89 59,6.9 80,8.67 73,5.0 67,7.42 58,10.03 63,7.7 49,4.91 78,10.35 54,6.84 52,5.62 76,10.43 59,8.39 60,5.97 68,9.63 59,6.78 62,9.32 56,8.39 68,7.71 54,8.73 58,7.64 58,6.48 57,8.05 57,8.43 78,9.79 56,6.29 58,6.44 55,9.65 62,8.41 48,8.44 65,8.42 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? 4 6 8 10 12 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 1.05 1.10 1.15 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.80 1.85 1.90 1.95 2.00 2.05 2.10 2.15 2.20 2.25 2.30 2.35 2.40 2.45 2.50 2.55 2.60 2.65 2.70 2.75 2.80 2.85 2.90 2.95 3.00 3.05 3.10 3.15 3.20 3.25 3.30 3.35 3.40 3.45 3.50 3.55 3.60 3.65 3.70 3.75 3.80 3.85 3.90 3.95 4.00 4.05 4.10 4.15 4.20 4.25 4.30 4.35 4.40 4.45 4.50 4.55 4.60 4.65 4.70 4.75 4.80 4.85 4.90 4.95 5.00 5.05 5.10 5.15 5.20 5.25 5.30 5.35 5.40 5.45 5.50 5.55 5.60 5.65 5.70 5.75 5.80 5.85 5.90 5.95 6.00 6.05 6.10 6.15 6.20 6.25 6.30 6.35 6.40 6.45 6.50 6.55 6.60 6.65 6.70 6.75 6.80 6.85 6.90 6.95 7.00 7.05 7.10 7.15 7.20 7.25 7.30 7.35 7.40 7.45 7.50 7.55 7.60 7.65 7.70 7.75 7.80 7.85 7.90 7.95 8.00 8.05 8.10 8.15 8.20 8.25 8.30 8.35 8.40 8.45 8.50 8.55 8.60 8.65 8.70 8.75 8.80 8.85 8.90 8.95 9.00 9.05 9.10 9.15 9.20 9.25 9.30 9.35 9.40 9.45 9.50 9.55 9.60 9.65 9.70 9.75 9.80 9.85 9.90 9.95 10.00 10.05 10.10 10.15 10.20 10.25 10.30 10.35 10.40 10.45 10.50 10.55 10.60 10.65 10.70 10.75 10.80 10.85 10.90 10.95 11.00 11.05 11.10 11.15 11.20 11.25 11.30 11.35 11.40 11.45 11.50 11.55 11.60 11.65 11.70 11.75 11.80 11.85 11.90 11.95 12.00 4 6 8 10 12 Breast milk intake (dl/day)
Figure 5: Relationship between breast-milk intake in infants and maternal weight, by sex. Lines represent linear regression models.
Interpretation

When we have non-parallel fitting curves as those shown in Figure 5, it means that the effect is not the same at different levels of the categorical variable. In other words, sex is an effect modifier, as has an interacting effect in the relationship between maternal weight and daily breast-milk intake.

Let’s add an interaction to our last model.

model_5 = lm(
    @formula(dl_milk ~ mat_weight * sex + mat_height),
    kfm; contrasts = kfm_cont
)

anova(model_5; type=3)
Analysis of Variance

Type 3 test / F test

dl_milk ~ 1 + mat_weight(centered: 59.96) + sex + mat_height(centered: 167.44) + mat_weight(centered: 59.96) & sex

Table:
───────────────────────────────────────────────────────────────────────────────────
                                   DOF     Exp.SS  Mean Square    F value  Pr(>|F|)
───────────────────────────────────────────────────────────────────────────────────
(Intercept)                          1  2798.51      2798.51    1779.1254    <1e-37
mat_weight(centered: 59.96)          1     4.9998       4.9998     3.1786    0.0814
sex                                  1     6.8740       6.8740     4.3701    0.0423
mat_height(centered: 167.44)         1     6.5367       6.5367     4.1556    0.0474
mat_weight(centered: 59.96) & sex    1     2.2604       2.2604     1.4370    0.2369
(Residuals)                         45    70.78         1.5730               
───────────────────────────────────────────────────────────────────────────────────
bic(model_4) |> r3, bic(model_5) |> r3
(180.406, 182.746)
Interpretation

From a statistical point of view, we prefer model_4 over model_5 as it has fewer number of parameters and the contribution of the interaction term is not statistically significant.

3.3 Stratification

Statistics do not tell the whole story, it helps us to understand our variables, to make inferences, to assess if a given difference is the result of chance. We still need to use common sense and the theory of our field (in my case, health sciences and biology) to interpret results.

The interaction term is not statistically significant and is likely that a statistician would recommend to remove it from our model. It would make sense from a statistical point of view.

The relationship between maternal weight and daily breast-milk intake is not the same between boys and girls. It is common and expected to find differences in clinical parameters between sexes.

From our scatter plot, we know that though the effect of maternal weight on breast-milk intake is positive for both sexes, the magnitude of such effect is not the same.

We will fit a regression model for boys and another regression model for girls, i.e., the stratified approach.

First we create our subsets:

boys = @subset(kfm, :sex == "Boy")
girls = @subset(kfm, :sex == "Girl");

Contrasts for the models (centring):

sex_cont = Dict(
    :mat_weight => Center(),
    :mat_height => Center()
);
model_boy = lm(
    @formula(dl_milk ~ mat_weight + mat_height),
    boys; contrasts=sex_cont
)
StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}}, Matrix{Float64}}

dl_milk ~ 1 + mat_weight(centered: 60.4) + mat_height(centered: 168.2)

Coefficients:
──────────────────────────────────────────────────────────────────────────────────────────
                                 Coef.  Std. Error      t  Pr(>|t|)   Lower 95%  Upper 95%
──────────────────────────────────────────────────────────────────────────────────────────
(Intercept)                  7.9524      0.239467   33.21    <1e-19   7.45578     8.44902
mat_weight(centered: 60.4)   0.102837    0.0403624   2.55    0.0183   0.0191306   0.186544
mat_height(centered: 168.2)  0.0234938   0.043485    0.54    0.5944  -0.0666886   0.113676
──────────────────────────────────────────────────────────────────────────────────────────
model_girl = lm(
    @formula(dl_milk ~ mat_weight + mat_height),
    girls; contrasts=sex_cont
)
StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}}, Matrix{Float64}}

dl_milk ~ 1 + mat_weight(centered: 59.52) + mat_height(centered: 166.68)

Coefficients:
────────────────────────────────────────────────────────────────────────────────────────────
                                   Coef.  Std. Error      t  Pr(>|t|)   Lower 95%  Upper 95%
────────────────────────────────────────────────────────────────────────────────────────────
(Intercept)                   7.0564       0.253213   27.87    <1e-17   6.53127    7.58153
mat_weight(centered: 59.52)   0.00216142   0.0331063   0.07    0.9485  -0.0664968  0.0708196
mat_height(centered: 166.68)  0.134988     0.0537816   2.51    0.0199   0.0234518  0.246524
────────────────────────────────────────────────────────────────────────────────────────────
Interpretation

When adjusted by maternal height, maternal weight has a significant positive effect on the daily breast-milk intake of boys ( \(p\) = 0.018) but not in girls ( \(p\) = 0.949).

3.4 Table of coefficients

We can generate a table of coefficients with the name of the model, or a more clean version with coeftable.

model_4 |> coeftable |> DataFrame
4×7 DataFrame
Row Name Coef. Std. Error t Pr(>|t|) Lower 95% Upper 95%
String Float64 Float64 Float64 Float64 Float64 Float64
1 (Intercept) 7.5044 0.178209 42.1102 2.18433e-38 7.14568 7.86312
2 mat_weight(centered: 59.96) 0.0403486 0.02603 1.55008 0.127975 -0.012047 0.0927443
3 sex: Girl -0.368626 0.179482 -2.05384 0.0457003 -0.729904 -0.00734864
4 mat_height(centered: 167.44) 0.0810793 0.0336528 2.40929 0.0200438 0.0133397 0.148819
Note

The glm_coef function from pubh.jl also gives this table, rounding all values to 3 digits.

glm_coef(model_4 |> coeftable |> DataFrame, ratio=false)
4×5 DataFrame
Row Name Coef. Lower 95% Upper 95% Pr(>|t|)
String Float64 Float64 Float64 Float64
1 (Intercept) 7.504 7.146 7.863 0.0
2 mat_weight(centered: 59.96) 0.04 -0.012 0.093 0.128
3 sex: Girl -0.369 -0.73 -0.007 0.046
4 mat_height(centered: 167.44) 0.081 0.013 0.149 0.02
Warning

When using glm_coef, the default is to exponentiate coefficients and confidence intervals. For Gaussian errors, please use: ratio=false.

3.5 Diagnostics

The performance data frames:

boy_perf = model_perf(model_boy)
girl_perf = model_perf(model_girl);

3.5.1 Normality

let
    p1 = resid_plot(boy_perf, title = "Boys")
    p2 = resid_plot(girl_perf, title = "Girls")

    hstack(p1, p2)
end
Theoretical quantiles -3 -2 -1 0 1 2 3 -3.00 -2.75 -2.50 -2.25 -2.00 -1.75 -1.50 -1.25 -1.00 -0.75 -0.50 -0.25 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 -3.00 -2.98 -2.96 -2.94 -2.92 -2.90 -2.88 -2.86 -2.84 -2.82 -2.80 -2.78 -2.76 -2.74 -2.72 -2.70 -2.68 -2.66 -2.64 -2.62 -2.60 -2.58 -2.56 -2.54 -2.52 -2.50 -2.48 -2.46 -2.44 -2.42 -2.40 -2.38 -2.36 -2.34 -2.32 -2.30 -2.28 -2.26 -2.24 -2.22 -2.20 -2.18 -2.16 -2.14 -2.12 -2.10 -2.08 -2.06 -2.04 -2.02 -2.00 -1.98 -1.96 -1.94 -1.92 -1.90 -1.88 -1.86 -1.84 -1.82 -1.80 -1.78 -1.76 -1.74 -1.72 -1.70 -1.68 -1.66 -1.64 -1.62 -1.60 -1.58 -1.56 -1.54 -1.52 -1.50 -1.48 -1.46 -1.44 -1.42 -1.40 -1.38 -1.36 -1.34 -1.32 -1.30 -1.28 -1.26 -1.24 -1.22 -1.20 -1.18 -1.16 -1.14 -1.12 -1.10 -1.08 -1.06 -1.04 -1.02 -1.00 -0.98 -0.96 -0.94 -0.92 -0.90 -0.88 -0.86 -0.84 -0.82 -0.80 -0.78 -0.76 -0.74 -0.72 -0.70 -0.68 -0.66 -0.64 -0.62 -0.60 -0.58 -0.56 -0.54 -0.52 -0.50 -0.48 -0.46 -0.44 -0.42 -0.40 -0.38 -0.36 -0.34 -0.32 -0.30 -0.28 -0.26 -0.24 -0.22 -0.20 -0.18 -0.16 -0.14 -0.12 -0.10 -0.08 -0.06 -0.04 -0.02 0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98 1.00 1.02 1.04 1.06 1.08 1.10 1.12 1.14 1.16 1.18 1.20 1.22 1.24 1.26 1.28 1.30 1.32 1.34 1.36 1.38 1.40 1.42 1.44 1.46 1.48 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00 -3 0 3 2.43918899484137252.267548572355811 1.84656781643472411.415747549783795 1.52206847624641541.2061316753172506 1.28306972356199521.1145806810523475 1.08715745969223781.0689295591596673 0.91711561242448510.9857829644503152 0.76408611811917840.7416741743720427 0.62281808300173990.6249039692064882 0.489872701041040360.5405923066878687 0.36281230515091780.475451851898114 0.239784108906252120.4237599096115465 0.119282753852897090.16365978522217198 1.0658141036401502e-160.12421231802921984 -0.11928275385289672-0.2623185339009327 -0.23978410890625204-0.3453824661526168 -0.36281230515091756-0.4839765113540153 -0.48987270104104-0.5601430021407006 -0.6228180830017398-0.6843071518858441 -0.7640861181191781-0.76052703302026 -0.9171156124244849-0.9346848789363507 -1.0871574596922382-1.063363673237271 -1.2830697235619952-1.125902367746801 -1.5220684762464154-1.2882872035545632 -1.8465678164347243-1.5746604154847934 -2.4391889948413734-2.2086903733497003 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? -3 -2 -1 0 1 2 3 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 -2.66 -2.64 -2.62 -2.60 -2.58 -2.56 -2.54 -2.52 -2.50 -2.48 -2.46 -2.44 -2.42 -2.40 -2.38 -2.36 -2.34 -2.32 -2.30 -2.28 -2.26 -2.24 -2.22 -2.20 -2.18 -2.16 -2.14 -2.12 -2.10 -2.08 -2.06 -2.04 -2.02 -2.00 -1.98 -1.96 -1.94 -1.92 -1.90 -1.88 -1.86 -1.84 -1.82 -1.80 -1.78 -1.76 -1.74 -1.72 -1.70 -1.68 -1.66 -1.64 -1.62 -1.60 -1.58 -1.56 -1.54 -1.52 -1.50 -1.48 -1.46 -1.44 -1.42 -1.40 -1.38 -1.36 -1.34 -1.32 -1.30 -1.28 -1.26 -1.24 -1.22 -1.20 -1.18 -1.16 -1.14 -1.12 -1.10 -1.08 -1.06 -1.04 -1.02 -1.00 -0.98 -0.96 -0.94 -0.92 -0.90 -0.88 -0.86 -0.84 -0.82 -0.80 -0.78 -0.76 -0.74 -0.72 -0.70 -0.68 -0.66 -0.64 -0.62 -0.60 -0.58 -0.56 -0.54 -0.52 -0.50 -0.48 -0.46 -0.44 -0.42 -0.40 -0.38 -0.36 -0.34 -0.32 -0.30 -0.28 -0.26 -0.24 -0.22 -0.20 -0.18 -0.16 -0.14 -0.12 -0.10 -0.08 -0.06 -0.04 -0.02 0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98 1.00 1.02 1.04 1.06 1.08 1.10 1.12 1.14 1.16 1.18 1.20 1.22 1.24 1.26 1.28 1.30 1.32 1.34 1.36 1.38 1.40 1.42 1.44 1.46 1.48 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 -3 0 3 Residuals Girls Theoretical quantiles -3 -2 -1 0 1 2 3 -3.00 -2.75 -2.50 -2.25 -2.00 -1.75 -1.50 -1.25 -1.00 -0.75 -0.50 -0.25 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 -3.00 -2.98 -2.96 -2.94 -2.92 -2.90 -2.88 -2.86 -2.84 -2.82 -2.80 -2.78 -2.76 -2.74 -2.72 -2.70 -2.68 -2.66 -2.64 -2.62 -2.60 -2.58 -2.56 -2.54 -2.52 -2.50 -2.48 -2.46 -2.44 -2.42 -2.40 -2.38 -2.36 -2.34 -2.32 -2.30 -2.28 -2.26 -2.24 -2.22 -2.20 -2.18 -2.16 -2.14 -2.12 -2.10 -2.08 -2.06 -2.04 -2.02 -2.00 -1.98 -1.96 -1.94 -1.92 -1.90 -1.88 -1.86 -1.84 -1.82 -1.80 -1.78 -1.76 -1.74 -1.72 -1.70 -1.68 -1.66 -1.64 -1.62 -1.60 -1.58 -1.56 -1.54 -1.52 -1.50 -1.48 -1.46 -1.44 -1.42 -1.40 -1.38 -1.36 -1.34 -1.32 -1.30 -1.28 -1.26 -1.24 -1.22 -1.20 -1.18 -1.16 -1.14 -1.12 -1.10 -1.08 -1.06 -1.04 -1.02 -1.00 -0.98 -0.96 -0.94 -0.92 -0.90 -0.88 -0.86 -0.84 -0.82 -0.80 -0.78 -0.76 -0.74 -0.72 -0.70 -0.68 -0.66 -0.64 -0.62 -0.60 -0.58 -0.56 -0.54 -0.52 -0.50 -0.48 -0.46 -0.44 -0.42 -0.40 -0.38 -0.36 -0.34 -0.32 -0.30 -0.28 -0.26 -0.24 -0.22 -0.20 -0.18 -0.16 -0.14 -0.12 -0.10 -0.08 -0.06 -0.04 -0.02 0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98 1.00 1.02 1.04 1.06 1.08 1.10 1.12 1.14 1.16 1.18 1.20 1.22 1.24 1.26 1.28 1.30 1.32 1.34 1.36 1.38 1.40 1.42 1.44 1.46 1.48 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00 -3 0 3 2.30676948324486152.208423062270863 1.74632072246239961.8068409063975417 1.43943791146965671.41785904030087 1.2134140033625031.063400116072998 1.02813749029035330.7997840606609923 0.86732693195256240.7696602454037504 0.72260515424429920.6716175294579192 0.58900632567625570.48429703865041385 0.463278327274386170.47437262300626126 0.343115828842235460.45187985362355954 0.226766628646573240.4509150451169513 0.112807091638736480.4227664973822694 -1.2789769243681803e-15-0.11822113935524214 -0.11280709163873888-0.13084760886916882 -0.2267666286465759-0.13203380078193974 -0.343115828842238-0.34942569948186714 -0.4632783272743886-0.4341107395933388 -0.5890063256762584-0.7711674725036869 -0.7226051542443018-1.054130014475305 -0.867326931952565-1.2147032646545555 -1.0281374902903562-1.2696089378914777 -1.2134140033625056-1.2970135034294308 -1.4394379114696594-1.3261687874565413 -1.7463207224624024-1.5545403065517678 -2.3067694832448646-1.724773006669464 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? -2 -1 0 1 2 3 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 -1.74 -1.72 -1.70 -1.68 -1.66 -1.64 -1.62 -1.60 -1.58 -1.56 -1.54 -1.52 -1.50 -1.48 -1.46 -1.44 -1.42 -1.40 -1.38 -1.36 -1.34 -1.32 -1.30 -1.28 -1.26 -1.24 -1.22 -1.20 -1.18 -1.16 -1.14 -1.12 -1.10 -1.08 -1.06 -1.04 -1.02 -1.00 -0.98 -0.96 -0.94 -0.92 -0.90 -0.88 -0.86 -0.84 -0.82 -0.80 -0.78 -0.76 -0.74 -0.72 -0.70 -0.68 -0.66 -0.64 -0.62 -0.60 -0.58 -0.56 -0.54 -0.52 -0.50 -0.48 -0.46 -0.44 -0.42 -0.40 -0.38 -0.36 -0.34 -0.32 -0.30 -0.28 -0.26 -0.24 -0.22 -0.20 -0.18 -0.16 -0.14 -0.12 -0.10 -0.08 -0.06 -0.04 -0.02 0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98 1.00 1.02 1.04 1.06 1.08 1.10 1.12 1.14 1.16 1.18 1.20 1.22 1.24 1.26 1.28 1.30 1.32 1.34 1.36 1.38 1.40 1.42 1.44 1.46 1.48 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 -2.5 0.0 2.5 Residuals Boys
Figure 6: QQ-Plots of residuals from models stratified by sex.

3.5.2 Homoscedasticity

let
    p1 = rvf_plot(boy_perf, title = "Boys")
    p2 = rvf_plot(girl_perf, title = "Girls")

    vstack(p1, p2)
end
Fitted values 5 6 7 8 9 5.0 5.2 5.4 5.6 5.8 6.0 6.2 6.4 6.6 6.8 7.0 7.2 7.4 7.6 7.8 8.0 8.2 8.4 8.6 8.8 9.0 4.98 5.00 5.02 5.04 5.06 5.08 5.10 5.12 5.14 5.16 5.18 5.20 5.22 5.24 5.26 5.28 5.30 5.32 5.34 5.36 5.38 5.40 5.42 5.44 5.46 5.48 5.50 5.52 5.54 5.56 5.58 5.60 5.62 5.64 5.66 5.68 5.70 5.72 5.74 5.76 5.78 5.80 5.82 5.84 5.86 5.88 5.90 5.92 5.94 5.96 5.98 6.00 6.02 6.04 6.06 6.08 6.10 6.12 6.14 6.16 6.18 6.20 6.22 6.24 6.26 6.28 6.30 6.32 6.34 6.36 6.38 6.40 6.42 6.44 6.46 6.48 6.50 6.52 6.54 6.56 6.58 6.60 6.62 6.64 6.66 6.68 6.70 6.72 6.74 6.76 6.78 6.80 6.82 6.84 6.86 6.88 6.90 6.92 6.94 6.96 6.98 7.00 7.02 7.04 7.06 7.08 7.10 7.12 7.14 7.16 7.18 7.20 7.22 7.24 7.26 7.28 7.30 7.32 7.34 7.36 7.38 7.40 7.42 7.44 7.46 7.48 7.50 7.52 7.54 7.56 7.58 7.60 7.62 7.64 7.66 7.68 7.70 7.72 7.74 7.76 7.78 7.80 7.82 7.84 7.86 7.88 7.90 7.92 7.94 7.96 7.98 8.00 8.02 8.04 8.06 8.08 8.10 8.12 8.14 8.16 8.18 8.20 8.22 8.24 8.26 8.28 8.30 8.32 8.34 8.36 8.38 8.40 8.42 8.44 8.46 8.48 8.50 8.52 8.54 8.56 8.58 8.60 8.62 8.64 8.66 8.68 8.70 8.72 8.74 8.76 8.78 8.80 8.82 8.84 8.86 8.88 8.90 8.92 8.94 8.96 8.98 9.00 5 10 6.532583366613708-0.5878590268274673 6.845787681970780.102471283807309 5.724817114080959-0.9031899331248127 7.7798961953043851.031296604008524 7.0746965703114550.13637016784399536 6.811204942682002-0.2897331112332288 7.638423986064689-0.22969109463109333 7.0898265187502960.9406075197728918 6.2669303177787060.530512407789321 6.1341037933612051.2753160994053905 6.414886790635047-1.1424883587694903 6.8609176304096210.8819595724951811 8.31120229297439-0.4712240557413579 6.166525111444435-0.8221021001468739 7.7971875649487740.6375461276177361 7.096310782366942-2.191373451353726 7.50775888285273750.45558167775236735 7.512081725263835-0.4142017456905599 6.1513951630055940.8815656230146017 6.4105639482239510.39551977218106676 8.043387822933838-0.9432592512935201 8.223765613873410.3681294347522082 6.7237682635810225-1.4220549922745274 8.195667138201276-0.6399011685775677 7.0963107823669422.420201999223633 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? -3 -2 -1 0 1 2 3 -3.00 -2.75 -2.50 -2.25 -2.00 -1.75 -1.50 -1.25 -1.00 -0.75 -0.50 -0.25 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 -3.00 -2.98 -2.96 -2.94 -2.92 -2.90 -2.88 -2.86 -2.84 -2.82 -2.80 -2.78 -2.76 -2.74 -2.72 -2.70 -2.68 -2.66 -2.64 -2.62 -2.60 -2.58 -2.56 -2.54 -2.52 -2.50 -2.48 -2.46 -2.44 -2.42 -2.40 -2.38 -2.36 -2.34 -2.32 -2.30 -2.28 -2.26 -2.24 -2.22 -2.20 -2.18 -2.16 -2.14 -2.12 -2.10 -2.08 -2.06 -2.04 -2.02 -2.00 -1.98 -1.96 -1.94 -1.92 -1.90 -1.88 -1.86 -1.84 -1.82 -1.80 -1.78 -1.76 -1.74 -1.72 -1.70 -1.68 -1.66 -1.64 -1.62 -1.60 -1.58 -1.56 -1.54 -1.52 -1.50 -1.48 -1.46 -1.44 -1.42 -1.40 -1.38 -1.36 -1.34 -1.32 -1.30 -1.28 -1.26 -1.24 -1.22 -1.20 -1.18 -1.16 -1.14 -1.12 -1.10 -1.08 -1.06 -1.04 -1.02 -1.00 -0.98 -0.96 -0.94 -0.92 -0.90 -0.88 -0.86 -0.84 -0.82 -0.80 -0.78 -0.76 -0.74 -0.72 -0.70 -0.68 -0.66 -0.64 -0.62 -0.60 -0.58 -0.56 -0.54 -0.52 -0.50 -0.48 -0.46 -0.44 -0.42 -0.40 -0.38 -0.36 -0.34 -0.32 -0.30 -0.28 -0.26 -0.24 -0.22 -0.20 -0.18 -0.16 -0.14 -0.12 -0.10 -0.08 -0.06 -0.04 -0.02 0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98 1.00 1.02 1.04 1.06 1.08 1.10 1.12 1.14 1.16 1.18 1.20 1.22 1.24 1.26 1.28 1.30 1.32 1.34 1.36 1.38 1.40 1.42 1.44 1.46 1.48 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00 -3 0 3 Std residuals Girls Fitted values 6 7 8 9 10 6.0 6.2 6.4 6.6 6.8 7.0 7.2 7.4 7.6 7.8 8.0 8.2 8.4 8.6 8.8 9.0 9.2 9.4 9.6 9.8 10.0 5.98 6.00 6.02 6.04 6.06 6.08 6.10 6.12 6.14 6.16 6.18 6.20 6.22 6.24 6.26 6.28 6.30 6.32 6.34 6.36 6.38 6.40 6.42 6.44 6.46 6.48 6.50 6.52 6.54 6.56 6.58 6.60 6.62 6.64 6.66 6.68 6.70 6.72 6.74 6.76 6.78 6.80 6.82 6.84 6.86 6.88 6.90 6.92 6.94 6.96 6.98 7.00 7.02 7.04 7.06 7.08 7.10 7.12 7.14 7.16 7.18 7.20 7.22 7.24 7.26 7.28 7.30 7.32 7.34 7.36 7.38 7.40 7.42 7.44 7.46 7.48 7.50 7.52 7.54 7.56 7.58 7.60 7.62 7.64 7.66 7.68 7.70 7.72 7.74 7.76 7.78 7.80 7.82 7.84 7.86 7.88 7.90 7.92 7.94 7.96 7.98 8.00 8.02 8.04 8.06 8.08 8.10 8.12 8.14 8.16 8.18 8.20 8.22 8.24 8.26 8.28 8.30 8.32 8.34 8.36 8.38 8.40 8.42 8.44 8.46 8.48 8.50 8.52 8.54 8.56 8.58 8.60 8.62 8.64 8.66 8.68 8.70 8.72 8.74 8.76 8.78 8.80 8.82 8.84 8.86 8.88 8.90 8.92 8.94 8.96 8.98 9.00 9.02 9.04 9.06 9.08 9.10 9.12 9.14 9.16 9.18 9.20 9.22 9.24 9.26 9.28 9.30 9.32 9.34 9.36 9.38 9.40 9.42 9.44 9.46 9.48 9.50 9.52 9.54 9.56 9.58 9.60 9.62 9.64 9.66 9.68 9.70 9.72 9.74 9.76 9.78 9.80 9.82 9.84 9.86 9.88 9.90 9.92 9.94 9.96 9.98 10.00 5 10 8.144596171485004-0.3878327536489946 6.634395160919387-1.5042345538077269 9.898597355213140.39377021657064143 7.219062222162098-0.33066579258744705 6.872424943519259-1.0925227110286648 9.9513554350031810.41753404902656405 7.9446923510870020.38845339383385646 7.695121787361843-1.5048684088702002 8.8232386111825130.7037588513587297 7.8977046618596045-0.975002720620483 8.1122405998457781.0535598008924176 7.65967487925973240.6370815153213433 8.987695523478404-1.1145668923339758 7.1720745329346991.3590187289595548 7.771373711765582-0.11460069082680661 7.8183614009929805-1.1674873082935278 7.5980550724441640.3942432638729744 7.64504276167156150.6847385262468421 9.92209119982684-0.11522657424271301 7.142810297758357-0.7439285071104111 7.747879867151884-1.1408974769741271 7.2514177938013242.092345372152836 7.9242898429361870.4236975479571782 6.4375826769842681.7467604854663872 8.538221139355242-0.1031273613142466 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? -2 -1 0 1 2 3 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 -2.00 -1.98 -1.96 -1.94 -1.92 -1.90 -1.88 -1.86 -1.84 -1.82 -1.80 -1.78 -1.76 -1.74 -1.72 -1.70 -1.68 -1.66 -1.64 -1.62 -1.60 -1.58 -1.56 -1.54 -1.52 -1.50 -1.48 -1.46 -1.44 -1.42 -1.40 -1.38 -1.36 -1.34 -1.32 -1.30 -1.28 -1.26 -1.24 -1.22 -1.20 -1.18 -1.16 -1.14 -1.12 -1.10 -1.08 -1.06 -1.04 -1.02 -1.00 -0.98 -0.96 -0.94 -0.92 -0.90 -0.88 -0.86 -0.84 -0.82 -0.80 -0.78 -0.76 -0.74 -0.72 -0.70 -0.68 -0.66 -0.64 -0.62 -0.60 -0.58 -0.56 -0.54 -0.52 -0.50 -0.48 -0.46 -0.44 -0.42 -0.40 -0.38 -0.36 -0.34 -0.32 -0.30 -0.28 -0.26 -0.24 -0.22 -0.20 -0.18 -0.16 -0.14 -0.12 -0.10 -0.08 -0.06 -0.04 -0.02 0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98 1.00 1.02 1.04 1.06 1.08 1.10 1.12 1.14 1.16 1.18 1.20 1.22 1.24 1.26 1.28 1.30 1.32 1.34 1.36 1.38 1.40 1.42 1.44 1.46 1.48 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00 -3 0 3 Std residuals Boys
Figure 7: Fitted vs residuals plot for the stratified models.
let
    p1 = variance_plot(boy_perf, title = "Boys")
    p2 = variance_plot(girl_perf, title = "Girls")

    vstack(p1, p2)
end
Fitted values 5 6 7 8 9 5.0 5.2 5.4 5.6 5.8 6.0 6.2 6.4 6.6 6.8 7.0 7.2 7.4 7.6 7.8 8.0 8.2 8.4 8.6 8.8 9.0 4.98 5.00 5.02 5.04 5.06 5.08 5.10 5.12 5.14 5.16 5.18 5.20 5.22 5.24 5.26 5.28 5.30 5.32 5.34 5.36 5.38 5.40 5.42 5.44 5.46 5.48 5.50 5.52 5.54 5.56 5.58 5.60 5.62 5.64 5.66 5.68 5.70 5.72 5.74 5.76 5.78 5.80 5.82 5.84 5.86 5.88 5.90 5.92 5.94 5.96 5.98 6.00 6.02 6.04 6.06 6.08 6.10 6.12 6.14 6.16 6.18 6.20 6.22 6.24 6.26 6.28 6.30 6.32 6.34 6.36 6.38 6.40 6.42 6.44 6.46 6.48 6.50 6.52 6.54 6.56 6.58 6.60 6.62 6.64 6.66 6.68 6.70 6.72 6.74 6.76 6.78 6.80 6.82 6.84 6.86 6.88 6.90 6.92 6.94 6.96 6.98 7.00 7.02 7.04 7.06 7.08 7.10 7.12 7.14 7.16 7.18 7.20 7.22 7.24 7.26 7.28 7.30 7.32 7.34 7.36 7.38 7.40 7.42 7.44 7.46 7.48 7.50 7.52 7.54 7.56 7.58 7.60 7.62 7.64 7.66 7.68 7.70 7.72 7.74 7.76 7.78 7.80 7.82 7.84 7.86 7.88 7.90 7.92 7.94 7.96 7.98 8.00 8.02 8.04 8.06 8.08 8.10 8.12 8.14 8.16 8.18 8.20 8.22 8.24 8.26 8.28 8.30 8.32 8.34 8.36 8.38 8.40 8.42 8.44 8.46 8.48 8.50 8.52 8.54 8.56 8.58 8.60 8.62 8.64 8.66 8.68 8.70 8.72 8.74 8.76 8.78 8.80 8.82 8.84 8.86 8.88 8.90 8.92 8.94 8.96 8.98 9.00 5 10 6.5325833666137080.8441465314823652 6.845787681970780.35243767963885453 5.7248171140809591.0463350869013992 7.7798961953043851.118080410657308 7.0746965703114550.40657524480536805 6.8112049426820020.5926254657724404 7.6384239860646890.5276589675772493 7.0898265187502961.0677890621511839 6.2669303177787060.8019162563642754 6.1341037933612051.2433407443813602 6.4148867906350471.176812130560799 6.8609176304096211.0339643947401567 8.311202292974390.7557792620695472 6.1665251114444350.9982610437377766 7.7971875649487740.8790975116852658 7.0963107823669421.629819248372942 7.50775888285273750.7431292735098403 7.5120817252638350.708577254266488 6.1513951630055941.0337334458139613 6.4105639482239510.6924132088399593 8.0433878229338381.0692931417220617 8.223765613873410.6680077740016135 6.72376826358102251.3129235558786438 8.1956671382012760.8807196706110728 7.0963107823669421.7128015698361143 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? 0.0 0.5 1.0 1.5 2.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.30 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.40 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.50 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.60 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.70 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.80 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.90 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.20 1.21 1.22 1.23 1.24 1.25 1.26 1.27 1.28 1.29 1.30 1.31 1.32 1.33 1.34 1.35 1.36 1.37 1.38 1.39 1.40 1.41 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.50 1.51 1.52 1.53 1.54 1.55 1.56 1.57 1.58 1.59 1.60 1.61 1.62 1.63 1.64 1.65 1.66 1.67 1.68 1.69 1.70 1.71 1.72 1.73 1.74 1.75 1.76 1.77 1.78 1.79 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.90 1.91 1.92 1.93 1.94 1.95 1.96 1.97 1.98 1.99 2.00 0 2 √|Std res| Girls Fitted values 6 7 8 9 10 6.0 6.2 6.4 6.6 6.8 7.0 7.2 7.4 7.6 7.8 8.0 8.2 8.4 8.6 8.8 9.0 9.2 9.4 9.6 9.8 10.0 5.98 6.00 6.02 6.04 6.06 6.08 6.10 6.12 6.14 6.16 6.18 6.20 6.22 6.24 6.26 6.28 6.30 6.32 6.34 6.36 6.38 6.40 6.42 6.44 6.46 6.48 6.50 6.52 6.54 6.56 6.58 6.60 6.62 6.64 6.66 6.68 6.70 6.72 6.74 6.76 6.78 6.80 6.82 6.84 6.86 6.88 6.90 6.92 6.94 6.96 6.98 7.00 7.02 7.04 7.06 7.08 7.10 7.12 7.14 7.16 7.18 7.20 7.22 7.24 7.26 7.28 7.30 7.32 7.34 7.36 7.38 7.40 7.42 7.44 7.46 7.48 7.50 7.52 7.54 7.56 7.58 7.60 7.62 7.64 7.66 7.68 7.70 7.72 7.74 7.76 7.78 7.80 7.82 7.84 7.86 7.88 7.90 7.92 7.94 7.96 7.98 8.00 8.02 8.04 8.06 8.08 8.10 8.12 8.14 8.16 8.18 8.20 8.22 8.24 8.26 8.28 8.30 8.32 8.34 8.36 8.38 8.40 8.42 8.44 8.46 8.48 8.50 8.52 8.54 8.56 8.58 8.60 8.62 8.64 8.66 8.68 8.70 8.72 8.74 8.76 8.78 8.80 8.82 8.84 8.86 8.88 8.90 8.92 8.94 8.96 8.98 9.00 9.02 9.04 9.06 9.08 9.10 9.12 9.14 9.16 9.18 9.20 9.22 9.24 9.26 9.28 9.30 9.32 9.34 9.36 9.38 9.40 9.42 9.44 9.46 9.48 9.50 9.52 9.54 9.56 9.58 9.60 9.62 9.64 9.66 9.68 9.70 9.72 9.74 9.76 9.78 9.80 9.82 9.84 9.86 9.88 9.90 9.92 9.94 9.96 9.98 10.00 5 10 8.1445961714850040.6667804522367192 6.6343951609193871.3131622751660919 9.898597355213140.671865049535143 7.2190622221620980.6156802921663953 6.8724249435192591.1191179310149841 9.9513554350031810.6918414305292928 7.9446923510870020.6673137559746529 7.6951217873618431.3134389164943465 8.8232386111825130.8981989695036887 7.89770466185960451.0572155228994722 8.1122405998457781.0989810736105614 7.65967487925973240.8545906158742138 8.9876955234784041.1303519467309304 7.1720745329346991.24816884557551 7.7713737117655820.3624551168980546 7.81836140099298051.1568757068038813 7.5980550724441640.6722684936510387 7.64504276167156150.8859781251974781 9.922091199826840.363443530451211 7.1428102977583570.9234772860002337 7.7478798671518841.1436257548480986 7.2514177938013241.548735679901085 7.9242898429361870.6969290904129435 6.4375826769842681.4150679570309448 8.5382211393552420.34383301085736684 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? 0.0 0.5 1.0 1.5 2.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.30 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.40 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.50 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.60 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.70 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.80 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.90 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.20 1.21 1.22 1.23 1.24 1.25 1.26 1.27 1.28 1.29 1.30 1.31 1.32 1.33 1.34 1.35 1.36 1.37 1.38 1.39 1.40 1.41 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.50 1.51 1.52 1.53 1.54 1.55 1.56 1.57 1.58 1.59 1.60 1.61 1.62 1.63 1.64 1.65 1.66 1.67 1.68 1.69 1.70 1.71 1.72 1.73 1.74 1.75 1.76 1.77 1.78 1.79 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.90 1.91 1.92 1.93 1.94 1.95 1.96 1.97 1.98 1.99 2.00 0 2 √|Std res| Boys

3.5.3 Influential observations

let
    p1 = cooks_plot(boy_perf, title = "Boys")
    p2 = cooks_plot(girl_perf, title = "Girls")

    vstack(p1, p2)
end
Index 0 5 10 15 20 25 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 11.0 11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 12.0 12.1 12.2 12.3 12.4 12.5 12.6 12.7 12.8 12.9 13.0 13.1 13.2 13.3 13.4 13.5 13.6 13.7 13.8 13.9 14.0 14.1 14.2 14.3 14.4 14.5 14.6 14.7 14.8 14.9 15.0 15.1 15.2 15.3 15.4 15.5 15.6 15.7 15.8 15.9 16.0 16.1 16.2 16.3 16.4 16.5 16.6 16.7 16.8 16.9 17.0 17.1 17.2 17.3 17.4 17.5 17.6 17.7 17.8 17.9 18.0 18.1 18.2 18.3 18.4 18.5 18.6 18.7 18.8 18.9 19.0 19.1 19.2 19.3 19.4 19.5 19.6 19.7 19.8 19.9 20.0 20.1 20.2 20.3 20.4 20.5 20.6 20.7 20.8 20.9 21.0 21.1 21.2 21.3 21.4 21.5 21.6 21.7 21.8 21.9 22.0 22.1 22.2 22.3 22.4 22.5 22.6 22.7 22.8 22.9 23.0 23.1 23.2 23.3 23.4 23.5 23.6 23.7 23.8 23.9 24.0 24.1 24.2 24.3 24.4 24.5 24.6 24.7 24.8 24.9 25.0 0 25 250.017015760378465975 240.00037885638061510346 230.068841750022075 220.03142403433970105 210.0010228499326321813 200.0024191074512282767 190.0014392895555274763 180.016872241182216866 170.01218548683589356 160.07408957144617757 150.0330816447322568 140.08217567283878396 130.023340798377971744 120.05488498284082162 110.016901701110225372 100.06761915941410863 90.004007718679247427 80.0033049791615143106 70.03355763806852983 60.004312251159524891 50.05186652408203241 40.021610961428265345 30.21520502524384388 20.023345750251496742 10.08247839605710139 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? 0.00 0.05 0.10 0.15 0.20 0.25 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.000 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.010 0.011 0.012 0.013 0.014 0.015 0.016 0.017 0.018 0.019 0.020 0.021 0.022 0.023 0.024 0.025 0.026 0.027 0.028 0.029 0.030 0.031 0.032 0.033 0.034 0.035 0.036 0.037 0.038 0.039 0.040 0.041 0.042 0.043 0.044 0.045 0.046 0.047 0.048 0.049 0.050 0.051 0.052 0.053 0.054 0.055 0.056 0.057 0.058 0.059 0.060 0.061 0.062 0.063 0.064 0.065 0.066 0.067 0.068 0.069 0.070 0.071 0.072 0.073 0.074 0.075 0.076 0.077 0.078 0.079 0.080 0.081 0.082 0.083 0.084 0.085 0.086 0.087 0.088 0.089 0.090 0.091 0.092 0.093 0.094 0.095 0.096 0.097 0.098 0.099 0.100 0.101 0.102 0.103 0.104 0.105 0.106 0.107 0.108 0.109 0.110 0.111 0.112 0.113 0.114 0.115 0.116 0.117 0.118 0.119 0.120 0.121 0.122 0.123 0.124 0.125 0.126 0.127 0.128 0.129 0.130 0.131 0.132 0.133 0.134 0.135 0.136 0.137 0.138 0.139 0.140 0.141 0.142 0.143 0.144 0.145 0.146 0.147 0.148 0.149 0.150 0.151 0.152 0.153 0.154 0.155 0.156 0.157 0.158 0.159 0.160 0.161 0.162 0.163 0.164 0.165 0.166 0.167 0.168 0.169 0.170 0.171 0.172 0.173 0.174 0.175 0.176 0.177 0.178 0.179 0.180 0.181 0.182 0.183 0.184 0.185 0.186 0.187 0.188 0.189 0.190 0.191 0.192 0.193 0.194 0.195 0.196 0.197 0.198 0.199 0.200 0.201 0.202 0.203 0.204 0.205 0.206 0.207 0.208 0.209 0.210 0.211 0.212 0.213 0.214 0.215 0.216 0.217 0.218 0.219 0.220 0.221 0.222 0.223 0.224 0.225 0.226 0.227 0.228 0.229 0.230 0.231 0.232 0.233 0.234 0.235 0.236 0.237 0.238 0.239 0.240 0.241 0.242 0.243 0.244 0.245 0.246 0.247 0.248 0.249 0.250 0.251 0.0 0.5 Cook's Distance Girls Index 0 5 10 15 20 25 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 11.0 11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 12.0 12.1 12.2 12.3 12.4 12.5 12.6 12.7 12.8 12.9 13.0 13.1 13.2 13.3 13.4 13.5 13.6 13.7 13.8 13.9 14.0 14.1 14.2 14.3 14.4 14.5 14.6 14.7 14.8 14.9 15.0 15.1 15.2 15.3 15.4 15.5 15.6 15.7 15.8 15.9 16.0 16.1 16.2 16.3 16.4 16.5 16.6 16.7 16.8 16.9 17.0 17.1 17.2 17.3 17.4 17.5 17.6 17.7 17.8 17.9 18.0 18.1 18.2 18.3 18.4 18.5 18.6 18.7 18.8 18.9 19.0 19.1 19.2 19.3 19.4 19.5 19.6 19.7 19.8 19.9 20.0 20.1 20.2 20.3 20.4 20.5 20.6 20.7 20.8 20.9 21.0 21.1 21.2 21.3 21.4 21.5 21.6 21.7 21.8 21.9 22.0 22.1 22.2 22.3 22.4 22.5 22.6 22.7 22.8 22.9 23.0 23.1 23.2 23.3 23.4 23.5 23.6 23.7 23.8 23.9 24.0 24.1 24.2 24.3 24.4 24.5 24.6 24.7 24.8 24.9 25.0 0 25 250.0040061071246065075 240.11186309647121993 230.024214111162230635 220.0025690089103932996 210.04887433929394291 200.026154013765447563 190.005673179998548114 180.13836305761028544 170.013884829942168343 160.023460441314565865 150.016117639024770862 140.030950077750665786 130.06311971218942146 120.04448515228113987 110.00031283254466251987 100.0486526720682556 90.002753206627943168 80.011084086905806763 70.0019201326078259339 60.07956917387710612 50.025897054670927656 40.10775784255585558 30.011678607112703094 20.18919568237853832 10.0002154552098606489 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? 0.00 0.05 0.10 0.15 0.20 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20 0.000 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.010 0.011 0.012 0.013 0.014 0.015 0.016 0.017 0.018 0.019 0.020 0.021 0.022 0.023 0.024 0.025 0.026 0.027 0.028 0.029 0.030 0.031 0.032 0.033 0.034 0.035 0.036 0.037 0.038 0.039 0.040 0.041 0.042 0.043 0.044 0.045 0.046 0.047 0.048 0.049 0.050 0.051 0.052 0.053 0.054 0.055 0.056 0.057 0.058 0.059 0.060 0.061 0.062 0.063 0.064 0.065 0.066 0.067 0.068 0.069 0.070 0.071 0.072 0.073 0.074 0.075 0.076 0.077 0.078 0.079 0.080 0.081 0.082 0.083 0.084 0.085 0.086 0.087 0.088 0.089 0.090 0.091 0.092 0.093 0.094 0.095 0.096 0.097 0.098 0.099 0.100 0.101 0.102 0.103 0.104 0.105 0.106 0.107 0.108 0.109 0.110 0.111 0.112 0.113 0.114 0.115 0.116 0.117 0.118 0.119 0.120 0.121 0.122 0.123 0.124 0.125 0.126 0.127 0.128 0.129 0.130 0.131 0.132 0.133 0.134 0.135 0.136 0.137 0.138 0.139 0.140 0.141 0.142 0.143 0.144 0.145 0.146 0.147 0.148 0.149 0.150 0.151 0.152 0.153 0.154 0.155 0.156 0.157 0.158 0.159 0.160 0.161 0.162 0.163 0.164 0.165 0.166 0.167 0.168 0.169 0.170 0.171 0.172 0.173 0.174 0.175 0.176 0.177 0.178 0.179 0.180 0.181 0.182 0.183 0.184 0.185 0.186 0.187 0.188 0.189 0.190 0.191 0.192 0.193 0.194 0.195 0.196 0.197 0.198 0.199 0.200 0.201 0.00 0.25 Cook's Distance Boys
Figure 8: Cook’s distance to detect potential outliers from the stratified models.
let
    p1 = res_lev_plot(boy_perf, title = "Boys")
    p2 = res_lev_plot(girl_perf, title = "Girls")

    vstack(p1, p2)
end
Leverage 0.00 0.05 0.10 0.15 0.20 0.25 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.000 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.010 0.011 0.012 0.013 0.014 0.015 0.016 0.017 0.018 0.019 0.020 0.021 0.022 0.023 0.024 0.025 0.026 0.027 0.028 0.029 0.030 0.031 0.032 0.033 0.034 0.035 0.036 0.037 0.038 0.039 0.040 0.041 0.042 0.043 0.044 0.045 0.046 0.047 0.048 0.049 0.050 0.051 0.052 0.053 0.054 0.055 0.056 0.057 0.058 0.059 0.060 0.061 0.062 0.063 0.064 0.065 0.066 0.067 0.068 0.069 0.070 0.071 0.072 0.073 0.074 0.075 0.076 0.077 0.078 0.079 0.080 0.081 0.082 0.083 0.084 0.085 0.086 0.087 0.088 0.089 0.090 0.091 0.092 0.093 0.094 0.095 0.096 0.097 0.098 0.099 0.100 0.101 0.102 0.103 0.104 0.105 0.106 0.107 0.108 0.109 0.110 0.111 0.112 0.113 0.114 0.115 0.116 0.117 0.118 0.119 0.120 0.121 0.122 0.123 0.124 0.125 0.126 0.127 0.128 0.129 0.130 0.131 0.132 0.133 0.134 0.135 0.136 0.137 0.138 0.139 0.140 0.141 0.142 0.143 0.144 0.145 0.146 0.147 0.148 0.149 0.150 0.151 0.152 0.153 0.154 0.155 0.156 0.157 0.158 0.159 0.160 0.161 0.162 0.163 0.164 0.165 0.166 0.167 0.168 0.169 0.170 0.171 0.172 0.173 0.174 0.175 0.176 0.177 0.178 0.179 0.180 0.181 0.182 0.183 0.184 0.185 0.186 0.187 0.188 0.189 0.190 0.191 0.192 0.193 0.194 0.195 0.196 0.197 0.198 0.199 0.200 0.201 0.202 0.203 0.204 0.205 0.206 0.207 0.208 0.209 0.210 0.211 0.212 0.213 0.214 0.215 0.216 0.217 0.218 0.219 0.220 0.221 0.222 0.223 0.224 0.225 0.226 0.227 0.228 0.229 0.230 0.231 0.232 0.233 0.234 0.235 0.236 0.237 0.238 0.239 0.240 0.241 0.242 0.243 0.244 0.245 0.246 0.247 0.248 0.249 0.250 0.251 0.0 0.5 0.07150954789712763-0.5878590268274673 0.0401538691887634860.102471283807309 0.16135256874083576-0.9031899331248127 0.12028648638309131.031296604008524 0.0406948155555101260.13637016784399536 0.04733161158319442-0.2897331112332288 0.04189988674837231-0.22969109463109333 0.068389933862896350.9406075197728918 0.040441780286565530.530512407789321 0.048015606562394281.2753160994053905 0.12463978133267542-1.1424883587694903 0.055730750026548530.8819595724951811 0.049632262005035344-0.4712240557413579 0.11334858745472734-0.8221021001468739 0.087222221855783340.6375461276177361 0.18110176948247889-2.191373451353726 0.060760866912517960.45558167775236735 0.04004437722488-0.4142017456905599 0.040551684494288940.8815656230146017 0.040570730159693370.39551977218106676 0.04050419400392983-0.9432592512935201 0.093668066536815420.3681294347522082 0.12716444505713034-1.4220549922745274 0.04272503401836168-0.6399011685775677 0.22225912262638252.420201999223633 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? -3 -2 -1 0 1 2 3 -3.00 -2.75 -2.50 -2.25 -2.00 -1.75 -1.50 -1.25 -1.00 -0.75 -0.50 -0.25 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 -3.00 -2.98 -2.96 -2.94 -2.92 -2.90 -2.88 -2.86 -2.84 -2.82 -2.80 -2.78 -2.76 -2.74 -2.72 -2.70 -2.68 -2.66 -2.64 -2.62 -2.60 -2.58 -2.56 -2.54 -2.52 -2.50 -2.48 -2.46 -2.44 -2.42 -2.40 -2.38 -2.36 -2.34 -2.32 -2.30 -2.28 -2.26 -2.24 -2.22 -2.20 -2.18 -2.16 -2.14 -2.12 -2.10 -2.08 -2.06 -2.04 -2.02 -2.00 -1.98 -1.96 -1.94 -1.92 -1.90 -1.88 -1.86 -1.84 -1.82 -1.80 -1.78 -1.76 -1.74 -1.72 -1.70 -1.68 -1.66 -1.64 -1.62 -1.60 -1.58 -1.56 -1.54 -1.52 -1.50 -1.48 -1.46 -1.44 -1.42 -1.40 -1.38 -1.36 -1.34 -1.32 -1.30 -1.28 -1.26 -1.24 -1.22 -1.20 -1.18 -1.16 -1.14 -1.12 -1.10 -1.08 -1.06 -1.04 -1.02 -1.00 -0.98 -0.96 -0.94 -0.92 -0.90 -0.88 -0.86 -0.84 -0.82 -0.80 -0.78 -0.76 -0.74 -0.72 -0.70 -0.68 -0.66 -0.64 -0.62 -0.60 -0.58 -0.56 -0.54 -0.52 -0.50 -0.48 -0.46 -0.44 -0.42 -0.40 -0.38 -0.36 -0.34 -0.32 -0.30 -0.28 -0.26 -0.24 -0.22 -0.20 -0.18 -0.16 -0.14 -0.12 -0.10 -0.08 -0.06 -0.04 -0.02 0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98 1.00 1.02 1.04 1.06 1.08 1.10 1.12 1.14 1.16 1.18 1.20 1.22 1.24 1.26 1.28 1.30 1.32 1.34 1.36 1.38 1.40 1.42 1.44 1.46 1.48 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00 -3 0 3 Std res Girls Leverage 0.00 0.05 0.10 0.15 0.20 0.25 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.000 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.010 0.011 0.012 0.013 0.014 0.015 0.016 0.017 0.018 0.019 0.020 0.021 0.022 0.023 0.024 0.025 0.026 0.027 0.028 0.029 0.030 0.031 0.032 0.033 0.034 0.035 0.036 0.037 0.038 0.039 0.040 0.041 0.042 0.043 0.044 0.045 0.046 0.047 0.048 0.049 0.050 0.051 0.052 0.053 0.054 0.055 0.056 0.057 0.058 0.059 0.060 0.061 0.062 0.063 0.064 0.065 0.066 0.067 0.068 0.069 0.070 0.071 0.072 0.073 0.074 0.075 0.076 0.077 0.078 0.079 0.080 0.081 0.082 0.083 0.084 0.085 0.086 0.087 0.088 0.089 0.090 0.091 0.092 0.093 0.094 0.095 0.096 0.097 0.098 0.099 0.100 0.101 0.102 0.103 0.104 0.105 0.106 0.107 0.108 0.109 0.110 0.111 0.112 0.113 0.114 0.115 0.116 0.117 0.118 0.119 0.120 0.121 0.122 0.123 0.124 0.125 0.126 0.127 0.128 0.129 0.130 0.131 0.132 0.133 0.134 0.135 0.136 0.137 0.138 0.139 0.140 0.141 0.142 0.143 0.144 0.145 0.146 0.147 0.148 0.149 0.150 0.151 0.152 0.153 0.154 0.155 0.156 0.157 0.158 0.159 0.160 0.161 0.162 0.163 0.164 0.165 0.166 0.167 0.168 0.169 0.170 0.171 0.172 0.173 0.174 0.175 0.176 0.177 0.178 0.179 0.180 0.181 0.182 0.183 0.184 0.185 0.186 0.187 0.188 0.189 0.190 0.191 0.192 0.193 0.194 0.195 0.196 0.197 0.198 0.199 0.200 0.201 0.202 0.203 0.204 0.205 0.206 0.207 0.208 0.209 0.210 0.211 0.212 0.213 0.214 0.215 0.216 0.217 0.218 0.219 0.220 0.221 0.222 0.223 0.224 0.225 0.226 0.227 0.228 0.229 0.230 0.231 0.232 0.233 0.234 0.235 0.236 0.237 0.238 0.239 0.240 0.241 0.242 0.243 0.244 0.245 0.246 0.247 0.248 0.249 0.250 0.251 0.0 0.5 0.041193026255290977-0.3878327536489946 0.21334204869144532-1.5042345538077269 0.14765265872106860.39377021657064143 0.06317358689172586-0.33066579258744705 0.14187728574024686-1.0925227110286648 0.15495654031644660.41753404902656405 0.0435861291569928640.38845339383385646 0.11359594367297812-1.5048684088702002 0.092704553105430690.7037588513587297 0.0657408521325036-0.975002720620483 0.075025914606969181.0535598008924176 0.0435861291569928640.6370815153213433 0.04110036440004932-1.1145668923339758 0.051323581341003591.3590187289595548 0.041827651346323574-0.11460069082680661 0.08059970872566051-1.1674873082935278 0.040178390176674770.3942432638729744 0.044271692050421830.6847385262468421 0.10323729210447577-0.11522657424271301 0.09175381400540869-0.7439285071104111 0.08283557861673002-1.1408974769741271 0.093968709507256192.092345372152836 0.043921419750413760.4236975479571782 0.044452446340396051.7467604854663872 0.0440946831870944-0.1031273613142466 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? -2 -1 0 1 2 3 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 -2.00 -1.98 -1.96 -1.94 -1.92 -1.90 -1.88 -1.86 -1.84 -1.82 -1.80 -1.78 -1.76 -1.74 -1.72 -1.70 -1.68 -1.66 -1.64 -1.62 -1.60 -1.58 -1.56 -1.54 -1.52 -1.50 -1.48 -1.46 -1.44 -1.42 -1.40 -1.38 -1.36 -1.34 -1.32 -1.30 -1.28 -1.26 -1.24 -1.22 -1.20 -1.18 -1.16 -1.14 -1.12 -1.10 -1.08 -1.06 -1.04 -1.02 -1.00 -0.98 -0.96 -0.94 -0.92 -0.90 -0.88 -0.86 -0.84 -0.82 -0.80 -0.78 -0.76 -0.74 -0.72 -0.70 -0.68 -0.66 -0.64 -0.62 -0.60 -0.58 -0.56 -0.54 -0.52 -0.50 -0.48 -0.46 -0.44 -0.42 -0.40 -0.38 -0.36 -0.34 -0.32 -0.30 -0.28 -0.26 -0.24 -0.22 -0.20 -0.18 -0.16 -0.14 -0.12 -0.10 -0.08 -0.06 -0.04 -0.02 0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98 1.00 1.02 1.04 1.06 1.08 1.10 1.12 1.14 1.16 1.18 1.20 1.22 1.24 1.26 1.28 1.30 1.32 1.34 1.36 1.38 1.40 1.42 1.44 1.46 1.48 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00 -3 0 3 Std res Boys
Figure 9: Residuals vs leverage plots.
let
    p1 = cook_lev_plot(boy_perf, title = "Boys")
    p2 = cook_lev_plot(girl_perf, title = "Girls")

    vstack(p1, p2)
end
Leverage 0.00 0.05 0.10 0.15 0.20 0.25 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.000 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.010 0.011 0.012 0.013 0.014 0.015 0.016 0.017 0.018 0.019 0.020 0.021 0.022 0.023 0.024 0.025 0.026 0.027 0.028 0.029 0.030 0.031 0.032 0.033 0.034 0.035 0.036 0.037 0.038 0.039 0.040 0.041 0.042 0.043 0.044 0.045 0.046 0.047 0.048 0.049 0.050 0.051 0.052 0.053 0.054 0.055 0.056 0.057 0.058 0.059 0.060 0.061 0.062 0.063 0.064 0.065 0.066 0.067 0.068 0.069 0.070 0.071 0.072 0.073 0.074 0.075 0.076 0.077 0.078 0.079 0.080 0.081 0.082 0.083 0.084 0.085 0.086 0.087 0.088 0.089 0.090 0.091 0.092 0.093 0.094 0.095 0.096 0.097 0.098 0.099 0.100 0.101 0.102 0.103 0.104 0.105 0.106 0.107 0.108 0.109 0.110 0.111 0.112 0.113 0.114 0.115 0.116 0.117 0.118 0.119 0.120 0.121 0.122 0.123 0.124 0.125 0.126 0.127 0.128 0.129 0.130 0.131 0.132 0.133 0.134 0.135 0.136 0.137 0.138 0.139 0.140 0.141 0.142 0.143 0.144 0.145 0.146 0.147 0.148 0.149 0.150 0.151 0.152 0.153 0.154 0.155 0.156 0.157 0.158 0.159 0.160 0.161 0.162 0.163 0.164 0.165 0.166 0.167 0.168 0.169 0.170 0.171 0.172 0.173 0.174 0.175 0.176 0.177 0.178 0.179 0.180 0.181 0.182 0.183 0.184 0.185 0.186 0.187 0.188 0.189 0.190 0.191 0.192 0.193 0.194 0.195 0.196 0.197 0.198 0.199 0.200 0.201 0.202 0.203 0.204 0.205 0.206 0.207 0.208 0.209 0.210 0.211 0.212 0.213 0.214 0.215 0.216 0.217 0.218 0.219 0.220 0.221 0.222 0.223 0.224 0.225 0.226 0.227 0.228 0.229 0.230 0.231 0.232 0.233 0.234 0.235 0.236 0.237 0.238 0.239 0.240 0.241 0.242 0.243 0.244 0.245 0.246 0.247 0.248 0.249 0.250 0.251 0.0 0.5 0.071509547897127630.017015760378465975 0.0401538691887634860.00037885638061510346 0.161352568740835760.068841750022075 0.12028648638309130.03142403433970105 0.0406948155555101260.0010228499326321813 0.047331611583194420.0024191074512282767 0.041899886748372310.0014392895555274763 0.068389933862896350.016872241182216866 0.040441780286565530.01218548683589356 0.048015606562394280.07408957144617757 0.124639781332675420.0330816447322568 0.055730750026548530.08217567283878396 0.0496322620050353440.023340798377971744 0.113348587454727340.05488498284082162 0.087222221855783340.016901701110225372 0.181101769482478890.06761915941410863 0.060760866912517960.004007718679247427 0.040044377224880.0033049791615143106 0.040551684494288940.03355763806852983 0.040570730159693370.004312251159524891 0.040504194003929830.05186652408203241 0.093668066536815420.021610961428265345 0.127164445057130340.21520502524384388 0.042725034018361680.023345750251496742 0.22225912262638250.08247839605710139 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? 0.00 0.05 0.10 0.15 0.20 0.25 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.000 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.010 0.011 0.012 0.013 0.014 0.015 0.016 0.017 0.018 0.019 0.020 0.021 0.022 0.023 0.024 0.025 0.026 0.027 0.028 0.029 0.030 0.031 0.032 0.033 0.034 0.035 0.036 0.037 0.038 0.039 0.040 0.041 0.042 0.043 0.044 0.045 0.046 0.047 0.048 0.049 0.050 0.051 0.052 0.053 0.054 0.055 0.056 0.057 0.058 0.059 0.060 0.061 0.062 0.063 0.064 0.065 0.066 0.067 0.068 0.069 0.070 0.071 0.072 0.073 0.074 0.075 0.076 0.077 0.078 0.079 0.080 0.081 0.082 0.083 0.084 0.085 0.086 0.087 0.088 0.089 0.090 0.091 0.092 0.093 0.094 0.095 0.096 0.097 0.098 0.099 0.100 0.101 0.102 0.103 0.104 0.105 0.106 0.107 0.108 0.109 0.110 0.111 0.112 0.113 0.114 0.115 0.116 0.117 0.118 0.119 0.120 0.121 0.122 0.123 0.124 0.125 0.126 0.127 0.128 0.129 0.130 0.131 0.132 0.133 0.134 0.135 0.136 0.137 0.138 0.139 0.140 0.141 0.142 0.143 0.144 0.145 0.146 0.147 0.148 0.149 0.150 0.151 0.152 0.153 0.154 0.155 0.156 0.157 0.158 0.159 0.160 0.161 0.162 0.163 0.164 0.165 0.166 0.167 0.168 0.169 0.170 0.171 0.172 0.173 0.174 0.175 0.176 0.177 0.178 0.179 0.180 0.181 0.182 0.183 0.184 0.185 0.186 0.187 0.188 0.189 0.190 0.191 0.192 0.193 0.194 0.195 0.196 0.197 0.198 0.199 0.200 0.201 0.202 0.203 0.204 0.205 0.206 0.207 0.208 0.209 0.210 0.211 0.212 0.213 0.214 0.215 0.216 0.217 0.218 0.219 0.220 0.221 0.222 0.223 0.224 0.225 0.226 0.227 0.228 0.229 0.230 0.231 0.232 0.233 0.234 0.235 0.236 0.237 0.238 0.239 0.240 0.241 0.242 0.243 0.244 0.245 0.246 0.247 0.248 0.249 0.250 0.251 0.0 0.5 Cook's Distance Girls Leverage 0.00 0.05 0.10 0.15 0.20 0.25 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.000 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.010 0.011 0.012 0.013 0.014 0.015 0.016 0.017 0.018 0.019 0.020 0.021 0.022 0.023 0.024 0.025 0.026 0.027 0.028 0.029 0.030 0.031 0.032 0.033 0.034 0.035 0.036 0.037 0.038 0.039 0.040 0.041 0.042 0.043 0.044 0.045 0.046 0.047 0.048 0.049 0.050 0.051 0.052 0.053 0.054 0.055 0.056 0.057 0.058 0.059 0.060 0.061 0.062 0.063 0.064 0.065 0.066 0.067 0.068 0.069 0.070 0.071 0.072 0.073 0.074 0.075 0.076 0.077 0.078 0.079 0.080 0.081 0.082 0.083 0.084 0.085 0.086 0.087 0.088 0.089 0.090 0.091 0.092 0.093 0.094 0.095 0.096 0.097 0.098 0.099 0.100 0.101 0.102 0.103 0.104 0.105 0.106 0.107 0.108 0.109 0.110 0.111 0.112 0.113 0.114 0.115 0.116 0.117 0.118 0.119 0.120 0.121 0.122 0.123 0.124 0.125 0.126 0.127 0.128 0.129 0.130 0.131 0.132 0.133 0.134 0.135 0.136 0.137 0.138 0.139 0.140 0.141 0.142 0.143 0.144 0.145 0.146 0.147 0.148 0.149 0.150 0.151 0.152 0.153 0.154 0.155 0.156 0.157 0.158 0.159 0.160 0.161 0.162 0.163 0.164 0.165 0.166 0.167 0.168 0.169 0.170 0.171 0.172 0.173 0.174 0.175 0.176 0.177 0.178 0.179 0.180 0.181 0.182 0.183 0.184 0.185 0.186 0.187 0.188 0.189 0.190 0.191 0.192 0.193 0.194 0.195 0.196 0.197 0.198 0.199 0.200 0.201 0.202 0.203 0.204 0.205 0.206 0.207 0.208 0.209 0.210 0.211 0.212 0.213 0.214 0.215 0.216 0.217 0.218 0.219 0.220 0.221 0.222 0.223 0.224 0.225 0.226 0.227 0.228 0.229 0.230 0.231 0.232 0.233 0.234 0.235 0.236 0.237 0.238 0.239 0.240 0.241 0.242 0.243 0.244 0.245 0.246 0.247 0.248 0.249 0.250 0.251 0.0 0.5 0.0411930262552909770.0040061071246065075 0.213342048691445320.11186309647121993 0.14765265872106860.024214111162230635 0.063173586891725860.0025690089103932996 0.141877285740246860.04887433929394291 0.15495654031644660.026154013765447563 0.0435861291569928640.005673179998548114 0.113595943672978120.13836305761028544 0.092704553105430690.013884829942168343 0.06574085213250360.023460441314565865 0.075025914606969180.016117639024770862 0.0435861291569928640.030950077750665786 0.041100364400049320.06311971218942146 0.051323581341003590.04448515228113987 0.0418276513463235740.00031283254466251987 0.080599708725660510.0486526720682556 0.040178390176674770.002753206627943168 0.044271692050421830.011084086905806763 0.103237292104475770.0019201326078259339 0.091753814005408690.07956917387710612 0.082835578616730020.025897054670927656 0.093968709507256190.10775784255585558 0.043921419750413760.011678607112703094 0.044452446340396050.18919568237853832 0.04409468318709440.0002154552098606489 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? 0.00 0.05 0.10 0.15 0.20 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20 0.000 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.010 0.011 0.012 0.013 0.014 0.015 0.016 0.017 0.018 0.019 0.020 0.021 0.022 0.023 0.024 0.025 0.026 0.027 0.028 0.029 0.030 0.031 0.032 0.033 0.034 0.035 0.036 0.037 0.038 0.039 0.040 0.041 0.042 0.043 0.044 0.045 0.046 0.047 0.048 0.049 0.050 0.051 0.052 0.053 0.054 0.055 0.056 0.057 0.058 0.059 0.060 0.061 0.062 0.063 0.064 0.065 0.066 0.067 0.068 0.069 0.070 0.071 0.072 0.073 0.074 0.075 0.076 0.077 0.078 0.079 0.080 0.081 0.082 0.083 0.084 0.085 0.086 0.087 0.088 0.089 0.090 0.091 0.092 0.093 0.094 0.095 0.096 0.097 0.098 0.099 0.100 0.101 0.102 0.103 0.104 0.105 0.106 0.107 0.108 0.109 0.110 0.111 0.112 0.113 0.114 0.115 0.116 0.117 0.118 0.119 0.120 0.121 0.122 0.123 0.124 0.125 0.126 0.127 0.128 0.129 0.130 0.131 0.132 0.133 0.134 0.135 0.136 0.137 0.138 0.139 0.140 0.141 0.142 0.143 0.144 0.145 0.146 0.147 0.148 0.149 0.150 0.151 0.152 0.153 0.154 0.155 0.156 0.157 0.158 0.159 0.160 0.161 0.162 0.163 0.164 0.165 0.166 0.167 0.168 0.169 0.170 0.171 0.172 0.173 0.174 0.175 0.176 0.177 0.178 0.179 0.180 0.181 0.182 0.183 0.184 0.185 0.186 0.187 0.188 0.189 0.190 0.191 0.192 0.193 0.194 0.195 0.196 0.197 0.198 0.199 0.200 0.201 0.00 0.25 Cook's Distance Boys
Figure 10: Cook’s distance vs leverage plots.

3.5.4 Performance statistics

@show r2(model_boy) |> r3; @show r2(model_girl) |> r3;
r2(model_boy) |> r3 = 0.409
r2(model_girl) |> r3 = 0.273
@show adjr2(model_boy) |> r3; @show adjr2(model_girl) |> r3;
adjr2(model_boy) |> r3 = 0.356
adjr2(model_girl) |> r3 = 0.207
@show mape(boy_perf) |> r3; @show mape(girl_perf) |> r3;
mape(boy_perf) |> r3 = 0.005
mape(girl_perf) |> r3 = 0.005
@show rmse(boy_perf) |> r3; @show rmse(girl_perf) |> r3;
rmse(boy_perf) |> r3 = 1.123
rmse(girl_perf) |> r3 = 1.188